gpt4 book ai didi

java - 通过 google 使用 Javax.mail 登录失败

转载 作者:太空宇宙 更新时间:2023-11-04 07:07:12 25 4
gpt4 key购买 nike

我已经在我的笔记本电脑上成功使用了以下代码,收件人收到了预期的邮件。但是,当将代码放入 jar 并从托管服务器运行时。我收到以下错误。

代码

    Properties props = new Properties();  
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.port", 465);
props.put("mail.smtp.socketFactory.port", 465);
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.ssl.enable", "true");
props.put("mail.transport.protocol", "smtp");
Session mailSession = null;

mailSession = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("emailadress", "password");
}
});

try {

Transport transport = mailSession.getTransport();

MimeMessage message = new MimeMessage(mailSession);

message.setSubject("Todays Email!:");
message.setFrom(new InternetAddress("theemailsender@gmail.com"));

message.addRecipients(Message.RecipientType.TO, InternetAddress.parse("recipient1@gmail.com"));

String body = theBody;
message.setContent(body,"text/html");
transport.connect();

transport.sendMessage(message,message.getAllRecipients());
transport.close();
} catch (Exception exception) {

}

错误

DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: STARTTLS requested but already using SSL
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN failed

此时我假设我必须将 startle.enable 或 ssl.enable 设置为 true,但不能同时设置两者。

最佳答案

按照以下步骤操作,您的问题有望得到解决

  • 首先登录您的 Gmail 帐户,然后单击以下路径: google account

    在安全 block 中,刚刚打开

    允许安全性较低的应用:开启

    希望它能拯救你的一天......祝你好运

关于java - 通过 google 使用 Javax.mail 登录失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21180966/

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