2014年に問題なく動作していた次のコードを使用しましたが、現在は動作しません。Java Mail APIを使用してメールを送信できない[Gmailを使用]
このコードで使用されている資格情報も正しいです。
public class SendMail
{
public void SendMailToTheUserWhoHaveForgotThePassword(String MailTo,String Password)
{
String to = MailTo;
String from = "[email protected]";
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からのメールを持っています。
Hi ChatNa,
Someone just tried to sign in to your Google Account [email protected] 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は、SSL/TLSプロトコルを使用してセキュリティを強化したいと考えています。ポート456または587を使用して、保護されたメール接続を設定するために必要なプロパティを追加します。 – glee8e
すべての例@ glee8e –
Googleにはいくつかのものがあると思います。私はスマートフォンを使用しており、スマートフォンでコード化するのは面倒です。 – glee8e