gpt4 book ai didi

JavaMail API AuthenticationFailedException

转载 作者:行者123 更新时间:2023-11-29 19:43:59 25 4
gpt4 key购买 nike

对不起我的英语!当我尝试使用 Android 中的 JavaMail API 从我的 gmail 帐户发送电子邮件时出现错误。我收到此错误:AuthenticationFailedException。我试过以下:带有密码的电子邮件地址是正确的(我也用另一个邮件地址进行了测试)。谷歌的设置是正确的。我用端口 465 进行了测试,然后我得到了另一个异常。我在互联网上搜索了 3 天,但没有找到任何帮助。

public class MailSending extends AsyncTask<Void, Void, Void> {
private String mail;
private String pass;
private String an;
private String betreff;
private String nachricht;

public MailSending(String mail, String pass, String an, String betreff, String nachricht) {
this.mail = mail;
this.pass = pass;
this.an = an;
this.betreff = betreff;
this.nachricht = nachricht;
}

@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
}

@Override
protected Void doInBackground(Void... params) {
final String host = "smtp.gmail.com";
Properties props = new Properties();

props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.port", "587");

Session ses = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(mail, pass);
}
});

try {
MimeMessage message = new MimeMessage(ses);
InternetAddress addressTo = new InternetAddress(an);
InternetAddress addressFrom = new InternetAddress(mail);

message.setFrom(addressFrom);
message.setRecipient(Message.RecipientType.TO, addressTo);
message.setSubject(betreff);
message.setContent(nachricht, "text/plain");

Transport.send(message);
Log.d("Nachricht:", "erfolgreich gesendet!");

} catch (MessagingException e) {
e.printStackTrace();
}
return null;
}

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.example.tuba.login.MailSending.doInBackground(MailSending.java:72)

W/System.err: at com.example.tuba.login.MailSending.doInBackground(MailSending.java:25)

W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288)

W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)

W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)

W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)

W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)

W/System.err: at java.lang.Thread.run(Thread.java:841)

最佳答案

你找到JavaMail FAQ了吗? ?

您很可能需要 enable less secure apps , 但没有看到 details of your exception很难确定。

关于JavaMail API AuthenticationFailedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38164189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com