gpt4 book ai didi

java - 无法使用 Java Mail API 发送邮件 [使用 Gmail]

转载 作者:行者123 更新时间:2023-12-01 09:45:50 26 4
gpt4 key购买 nike

我使用了以下代码,该代码在 2014 年运行良好,但目前无法运行。

此代码中使用的凭据也是正确的。

public class SendMail 
{
public void SendMailToTheUserWhoHaveForgotThePassword(String MailTo,String Password)
{
String to = MailTo;
String from = "chatna06062016@gmail.com";
final String username = "chatna06062016";
final String password = "xxxxxxxx";

String host = "smtp.gmail.com";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", "25");
Session session = Session.getInstance(props,new javax.mail.Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(username, password);
}
}
);

try
{
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to));
message.setSubject("FORGOTTEN PASSWORD");


message.setText("Dear User The Password that you have forgotten is <b>"+Password +"</b>"+
"This email is sended you by using JavaMailAPI "
+ "HAVE A NICE DAY"
+ "DO USE THIS SERVICE WHENEVER YOU NEED IT");

Transport.send(message);
System.out.println("Sent message successfully....");

}
catch (MessagingException e) {
throw new RuntimeException(e);
}

}

}

我收到了来自 google 的电子邮件,内容涉及上述类中使用的方法的用法。

Email Received from Google

Hi ChatNa,
Someone just tried to sign in to your Google Account chatna06062016@gmail.com from an app that doesn't meet modern security standards.
Details:
Sunday, June 26, 2016 12:57 PM (India Standard Time)
Noida, Uttar Pradesh, India*
We strongly recommend that you use a secure app, like Gmail, to access your account. All apps made by Google meet these security standards. Using a less secure app, on the other hand, could leave your account vulnerable. Learn more.

Google stopped this sign-in attempt, but you should review your recently used devices:

现在该怎么办,无法在任何地方找到任何有用的东西。

最佳答案

您可能需要在 Gmail 帐户中进行以下设置:

转到:myaccount -> 登录和安全 -> 连接的应用程序和网站 -> 允许安全性较低的应用程序:打开

关于java - 无法使用 Java Mail API 发送邮件 [使用 Gmail],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38036386/

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