【问题标题】:Error when send mail in java using javamail?使用javamail在java中发送邮件时出错?
【发布时间】:2015-03-16 23:43:42
【问题描述】:

我想使用 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.14https://support.google.com/mail/bin/answer.py?answer=78754gj16sm129363wic.24-gsmtp

我尝试了很多更改,但都是同样的错误。

【问题讨论】:

  • 与您的 Java 代码无关,谷歌不允许您发送邮件。
  • 你的意思是谷歌是问题吗?为什么?
  • 您是否点击了错误消息中的链接?您是否使用网络浏览器登录?您是否将您的帐户配置为允许安全性较低的应用访问?

标签: java jakarta-mail


【解决方案1】:

由于 Google 是垃圾邮件的一大目标,因此他们制定了政策和做法来尝试尽可能多地阻止垃圾邮件。您的帐户可能已被其中一项政策标记,需要一些人工干预才能使其再次运行。

【讨论】:

    猜你喜欢
    • 2010-11-12
    • 1970-01-01
    • 1970-01-01
    • 2015-08-10
    • 1970-01-01
    • 2012-08-25
    • 2014-09-26
    • 2013-04-27
    相关资源
    最近更新 更多