Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 由于AuthenticationException,无法使用smtp发送邮件_Android_Email_Authentication_Smtp Auth - Fatal编程技术网

Android 由于AuthenticationException,无法使用smtp发送邮件

Android 由于AuthenticationException,无法使用smtp发送邮件,android,email,authentication,smtp-auth,Android,Email,Authentication,Smtp Auth,我使用下面的类来发送邮件,但作为响应,我得到了一些异常,我已经粘贴在这里。用户名和密码正确,可能的错误原因是什么 代码: package com.mailsend; 导入android.util.Log; 导入java.util.Date; 导入java.util.Properties; 导入javax.activation.CommandMap; 导入javax.activation.DataHandler; 导入javax.activation.DataSource; 导入javax.act

我使用下面的类来发送邮件,但作为响应,我得到了一些异常,我已经粘贴在这里。用户名和密码正确,可能的错误原因是什么

代码:

package com.mailsend;
导入android.util.Log;
导入java.util.Date;
导入java.util.Properties;
导入javax.activation.CommandMap;
导入javax.activation.DataHandler;
导入javax.activation.DataSource;
导入javax.activation.FileDataSource;
导入javax.activation.MailcapCommandMap;
导入javax.mail.BodyPart;
导入javax.mail.Multipart;
导入javax.mail.PasswordAuthentication;
导入javax.mail.Session;
导入javax.mail.Transport;
导入javax.mail.internet.InternetAddress;
导入javax.mail.internet.MimeBodyPart;
导入javax.mail.internet.mimessage;
导入javax.mail.internet.MimeMultipart;
公共类邮件扩展了javax.Mail.Authenticator{
私有字符串用户;
私人字符串传递;
私有类型;
私有字符串[]_至;
私有字符串_来自;
专用字符串\u端口;
私人弦乐运动;
私有字符串\u主机;
私有字符串(subject);;
私有字符串(body),;
私有布尔认证;
私有布尔可调试;
私有多部分_多部分;
公共邮件(){
_host=“smtp.gmail.com”;//默认smtp服务器
_port=“465”;//默认smtp端口
_sport=“465”//默认socketfactory端口
_user=”“;//用户名
_pass=”“;//密码
_from=”“;//从发送的电子邮件
_subject=”“;//电子邮件主题
_body=”“;//电子邮件正文
_debuggable=true;//打开或关闭调试模式-默认关闭
_auth=true;//smtp身份验证-默认为打开
_multipart=新的MimeMultipart();
MailcapCommandMap mc=(MailcapCommandMap)CommandMap
.getDefaultCommandMap();
mc.addMailcap(“text/html;x-java-content-handler=com.sun.mail.handlers.text_html”);
mc.addMailcap(“text/xml;x-java-content-handler=com.sun.mail.handlers.text_xml”);
mc.addMailcap(“text/plain;;x-java-content-handler=com.sun.mail.handlers.text_plain”);
mc.addMailcap(“multipart/*;x-java-content-handler=com.sun.mail.handlers.multipart_mixed”);
mc.addMailcap(“message/rfc822;;x-java-content-handler=com.sun.mail.handlers.message_rfc822”);
setDefaultCommandMap(mc);
}
公共邮件(最终字符串用户、最终字符串传递、int-emailType){
这个();
_用户=用户;
_通过=通过;
this.emailType=emailType;
}
公共布尔发送(){
试一试{
Properties props=_setProperties();
如果(!\u user.equals(“”&)&!\u pass.equals(“”&&)to.length>0
&&!\u from.equals(“”)&!\u subject.equals(“”)
&&!\u正文。等于(“”){
//props.put(“mail.smtp.user”,\u from);
Session Session=Session.getInstance(props,this);
//Session Session=Session.getInstance(道具、新邮件、,
//(u pass),;
MimeMessage msg=新MimeMessage(会话);
msg.setFrom(新的Internet地址(_-from));
InternetAddress[]addressTo=新的InternetAddress[_to.length];
对于(int i=0;i<\u to.length;i++){
addressTo[i]=新的Internet地址(_to[i]);
}
msg.setRecipients(mimessage.RecipientType.TO,addressTo);
msg.setSubject(_subject);
msg.setSentDate(新日期());
如果(emailType==1){
BodyPart messageBodyPart=新的MimeBodyPart();
messageBodyPart.setText(_body);
_multipart.addBodyPart(messageBodyPart);
msg.setContent(_多部分);
}else if(emailType==2){
msg.setText(_body,“utf-8”,“html”);
}
//发送电子邮件
发送(msg);
Log.d(“usm_邮件”、“sendind消息”+_正文);
返回true;
}否则{
返回false;
}
}
catch(异常e){e.printStackTrace();}
返回false;
}
public void addAttachment(字符串文件名)引发异常{
BodyPart messageBodyPart=新的MimeBodyPart();
DataSource source=新文件DataSource(文件名);
setDataHandler(新的DataHandler(源));
messageBodyPart.setFileName(文件名);
_multipart.addBodyPart(messageBodyPart);
}
@凌驾
公共密码身份验证getPasswordAuthentication(){
返回新密码身份验证(_user,_pass);
}
私有属性_setProperties(){
Properties props=新属性();
props.put(“mail.smtp.host”,\u host);
如果(_可调试){
props.put(“mail.debug”,“true”);
}
如果(_auth){
props.put(“mail.smtp.auth”,“true”);
}
props.put(“mail.smtp.port”,_-port);
props.put(“mail.smtp.socketFactory.port”,_sport);
put(“mail.smtp.socketFactory.class”、“javax.net.ssl.SSLSocketFactory”);
props.put(“mail.smtp.socketFactory.fallback”、“false”);
返回道具;
}
//接球手和二传手
公共字符串getBody(){
返回体;
}
公共体(字符串_体){
这个。_body=_body;
}
public void setTo(字符串[]toArr){
//TODO自动生成的方法存根
这个。_to=toArr;
}
公共void setFrom(字符串){
//TODO自动生成的方法存根
这个。_from=string;
}
public void setSubject(字符串){
//TODO自动生成的方法存根
这个。_subject=string;
}
//更多的能手和二传手�..
}
例外情况:

System.out: DEBUG: JavaMail version 1.4.1
I/System.out: DEBUG: not loading file: /system/lib/javamail.providers
I/System.out: DEBUG: java.io.FileNotFoundException: /system/lib/javamail.providers: open failed: ENOENT (No such file or directory)
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
I/System.out: DEBUG: !anyLoaded
I/System.out: DEBUG: not loading resource: /META-INF/javamail.providers
I/System.out: DEBUG: not loading resource: /META-INF/javamail.default.providers
I/System.out: DEBUG: failed to load any providers, using defaults
I/System.out: DEBUG: Tables of loaded providers
I/System.out: DEBUG: Providers Listed By Class Name: {com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc.,1.4.1], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc.,1.4.1], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc.,1.4.1], com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc.,1.4.1], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc.,1.4.1], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc.,1.4.1]}
I/System.out: DEBUG: Providers Listed By Protocol: {pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc.,1.4.1], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc.,1.4.1], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc.,1.4.1], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc.,1.4.1], imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc.,1.4.1], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc.,1.4.1]}
I/System.out: DEBUG: not loading resource: /META-INF/javamail.default.address.map
I/System.out: DEBUG: !anyLoaded
I/System.out: DEBUG: not loading resource: /META-INF/javamail.address.map
I/System.out: DEBUG: not loading file: /system/lib/javamail.address.map
I/System.out: DEBUG: java.io.FileNotFoundException: /system/lib/javamail.address.map: open failed: ENOENT (No such file or directory)
I/System.out: DEBUG: failed to load address map, using defaults
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
I/System.out: DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc.,1.4.1]
I/System.out: DEBUG SMTP: useEhlo true, useAuth true
I/System.out: DEBUG SMTP: useEhlo true, useAuth true
I/System.out: DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
I/System.out: 220 smtp.gmail.com ESMTP s136sm11447877pgc.38 - gsmtp
I/System.out: DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
I/System.out: EHLO localhost
I/System.out: 250-smtp.gmail.com at your service, [202.166.173.132]
I/System.out: 250-SIZE 35882577
I/System.out: 250-8BITMIME
I/System.out: 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
I/System.out: 250-ENHANCEDSTATUSCODES
I/System.out: 250-PIPELINING
I/System.out: 250-CHUNKING
I/System.out: 250 SMTPUTF8
I/System.out: DEBUG SMTP: Found extension "SIZE", arg "35882577"
I/System.out: DEBUG SMTP: Found extension "8BITMIME", arg ""
I/System.out: DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH"
I/System.out: DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
I/System.out: DEBUG SMTP: Found extension "PIPELINING", arg ""
I/System.out: DEBUG SMTP: Found extension "CHUNKING", arg ""
I/System.out: DEBUG SMTP: Found extension "SMTPUTF8", arg ""
I/System.out: DEBUG SMTP: Attempt to authenticate
I/System.out: AUTH LOGIN
I/System.out: 334 VXNlcm5hbWU6
I/System.out: dmVsb2Zvb2RyMUBnbWFpbC5jb20=
I/System.out: 334 UGFzc3dvcmQ6
I/System.out: eTF5MnkzeTQ=
I/System.out: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbsq
I/System.out: 534-5.7.14 FA9KEamJQo2BxbjXpwkW-oz0-yU2OUblChDH9fx85CwWNKILKOzTk4TDoV5_QoS16XYYhA
I/System.out: 534-5.7.14 EPVtOfrH8jQV1PCdWUEm5UzNG6dlEwDt61I6NX0GBl7Mox6bcf_CZbUJsb9nJBlOV8xYmn
I/System.out: 534-5.7.14 z6cleMLGilD11Ip28kdjuAd27XwUqYPS4TTjna3CwJHZD-IBL10o1TTU3JmDo_DvTEA395
I/System.out: 534-5.7.14 qcLXXeO1h58qBU8OkP1J9KQM5GUs8> Please log in via your web browser and
I/System.out: 534-5.7.14 then try again.
I/System.out: 534-5.7.14  Learn more at
I/System.out: 534 5.7.14  https://support.google.com/mail/answer/78754 s136sm11447877pgc.38 - gsmtp
W/System.err: javax.mail.AuthenticationFailedException
W/System.err:     at javax.mail.Service.connect(Service.java:319)
W/System.err:     at javax.mail.Service.connect(Service.java:169)
W/System.err:     at javax.mail.Service.connect(Service.java:118)
W/System.err:     at javax.mail.Transport.send0(Transport.java:188)
W/System.err:     at javax.mail.Transport.send(Transport.java:118)
W/System.err:     at com.mailsend.Mail.send(Mail.java:113)
W/System.err:     at com.restaurant.app.DashboardActivity$Send_Mail_Task.doInBackground(DashboardActivity.java:183)
W/System.err:     at com.restaurant.app.DashboardActivity$Send_Mail_Task.doInBackground(DashboardActivity.java:131)
W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:295)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
W/System.err:     at java.lang.Thread.run(Thread.java:818)
System.ou
System.out: DEBUG: JavaMail version 1.4.1
I/System.out: DEBUG: not loading file: /system/lib/javamail.providers
I/System.out: DEBUG: java.io.FileNotFoundException: /system/lib/javamail.providers: open failed: ENOENT (No such file or directory)
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
I/System.out: DEBUG: !anyLoaded
I/System.out: DEBUG: not loading resource: /META-INF/javamail.providers
I/System.out: DEBUG: not loading resource: /META-INF/javamail.default.providers
I/System.out: DEBUG: failed to load any providers, using defaults
I/System.out: DEBUG: Tables of loaded providers
I/System.out: DEBUG: Providers Listed By Class Name: {com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc.,1.4.1], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc.,1.4.1], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc.,1.4.1], com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc.,1.4.1], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc.,1.4.1], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc.,1.4.1]}
I/System.out: DEBUG: Providers Listed By Protocol: {pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc.,1.4.1], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc.,1.4.1], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc.,1.4.1], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc.,1.4.1], imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc.,1.4.1], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc.,1.4.1]}
I/System.out: DEBUG: not loading resource: /META-INF/javamail.default.address.map
I/System.out: DEBUG: !anyLoaded
I/System.out: DEBUG: not loading resource: /META-INF/javamail.address.map
I/System.out: DEBUG: not loading file: /system/lib/javamail.address.map
I/System.out: DEBUG: java.io.FileNotFoundException: /system/lib/javamail.address.map: open failed: ENOENT (No such file or directory)
I/System.out: DEBUG: failed to load address map, using defaults
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
I/System.out: DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc.,1.4.1]
I/System.out: DEBUG SMTP: useEhlo true, useAuth true
I/System.out: DEBUG SMTP: useEhlo true, useAuth true
I/System.out: DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
I/System.out: 220 smtp.gmail.com ESMTP s136sm11447877pgc.38 - gsmtp
I/System.out: DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
I/System.out: EHLO localhost
I/System.out: 250-smtp.gmail.com at your service, [202.166.173.132]
I/System.out: 250-SIZE 35882577
I/System.out: 250-8BITMIME
I/System.out: 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
I/System.out: 250-ENHANCEDSTATUSCODES
I/System.out: 250-PIPELINING
I/System.out: 250-CHUNKING
I/System.out: 250 SMTPUTF8
I/System.out: DEBUG SMTP: Found extension "SIZE", arg "35882577"
I/System.out: DEBUG SMTP: Found extension "8BITMIME", arg ""
I/System.out: DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH"
I/System.out: DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
I/System.out: DEBUG SMTP: Found extension "PIPELINING", arg ""
I/System.out: DEBUG SMTP: Found extension "CHUNKING", arg ""
I/System.out: DEBUG SMTP: Found extension "SMTPUTF8", arg ""
I/System.out: DEBUG SMTP: Attempt to authenticate
I/System.out: AUTH LOGIN
I/System.out: 334 VXNlcm5hbWU6
I/System.out: dmVsb2Zvb2RyMUBnbWFpbC5jb20=
I/System.out: 334 UGFzc3dvcmQ6
I/System.out: eTF5MnkzeTQ=
I/System.out: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbsq
I/System.out: 534-5.7.14 FA9KEamJQo2BxbjXpwkW-oz0-yU2OUblChDH9fx85CwWNKILKOzTk4TDoV5_QoS16XYYhA
I/System.out: 534-5.7.14 EPVtOfrH8jQV1PCdWUEm5UzNG6dlEwDt61I6NX0GBl7Mox6bcf_CZbUJsb9nJBlOV8xYmn
I/System.out: 534-5.7.14 z6cleMLGilD11Ip28kdjuAd27XwUqYPS4TTjna3CwJHZD-IBL10o1TTU3JmDo_DvTEA395
I/System.out: 534-5.7.14 qcLXXeO1h58qBU8OkP1J9KQM5GUs8> Please log in via your web browser and
I/System.out: 534-5.7.14 then try again.
I/System.out: 534-5.7.14  Learn more at
I/System.out: 534 5.7.14  https://support.google.com/mail/answer/78754 s136sm11447877pgc.38 - gsmtp
W/System.err: javax.mail.AuthenticationFailedException
W/System.err:     at javax.mail.Service.connect(Service.java:319)
W/System.err:     at javax.mail.Service.connect(Service.java:169)
W/System.err:     at javax.mail.Service.connect(Service.java:118)
W/System.err:     at javax.mail.Transport.send0(Transport.java:188)
W/System.err:     at javax.mail.Transport.send(Transport.java:118)
W/System.err:     at com.mailsend.Mail.send(Mail.java:113)
W/System.err:     at com.restaurant.app.DashboardActivity$Send_Mail_Task.doInBackground(DashboardActivity.java:183)
W/System.err:     at com.restaurant.app.DashboardActivity$Send_Mail_Task.doInBackground(DashboardActivity.java:131)
W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:295)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
W/System.err:     at java.lang.Thread.run(Thread.java:818)
transport = session.getTransport("smtp");
transport.connect(host, username, pass);
transport.sendMessage(message, message.getAllRecipients())
properties.put("mail.smtp.starttls.enable", "true")