使用 java 邮件在 java 中发送邮件时出错?
Error when send mail in java using javamail?
我想使用 javamail 所以我测试了这段代码
public class Test_Mail {
public static void main(String [] args)
{
String to="xyz@gmail.com";//change accordingly
//Get the session object
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("abc@gmail.com","*****");
}
});
//compose message
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress("abc@gmail.com"));//change accordingly
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("Hello");
message.setText("Testing.......");
//send message
Transport.send(message);
System.out.println("message sent successfully");
} catch (MessagingException e) {throw new RuntimeException(e);}
}
}
但是我有这个错误:
线程异常 "main" java.lang.RuntimeException: javax.mail.AuthenticationFailedException: 534-5.7.14 请通过网络浏览器登录并
534-5.7.14 然后重试。
534-5.7.14 了解更多信息
534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 gj16sm129363wic.24-gsmtp
我尝试了很多更改,但都是同样的错误。
因为 Google 是垃圾邮件的一个大目标,他们制定了政策和实践来尝试尽可能多地防止垃圾邮件。看来您的帐户可能已被其中一项政策标记,需要一些手动干预才能使其恢复正常。
我想使用 javamail 所以我测试了这段代码
public class Test_Mail {
public static void main(String [] args)
{
String to="xyz@gmail.com";//change accordingly
//Get the session object
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("abc@gmail.com","*****");
}
});
//compose message
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress("abc@gmail.com"));//change accordingly
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("Hello");
message.setText("Testing.......");
//send message
Transport.send(message);
System.out.println("message sent successfully");
} catch (MessagingException e) {throw new RuntimeException(e);}
}
}
但是我有这个错误:
线程异常 "main" java.lang.RuntimeException: javax.mail.AuthenticationFailedException: 534-5.7.14 请通过网络浏览器登录并 534-5.7.14 然后重试。 534-5.7.14 了解更多信息 534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 gj16sm129363wic.24-gsmtp
我尝试了很多更改,但都是同样的错误。
因为 Google 是垃圾邮件的一个大目标,他们制定了政策和实践来尝试尽可能多地防止垃圾邮件。看来您的帐户可能已被其中一项政策标记,需要一些手动干预才能使其恢复正常。