我只有在尝试使用javax库发送邮件时才会收到此错误。如果我从我的邮件客户端发送它,它工作正常。
Properties properties = new Properties();
properties.put("mail.transport.protocol", "smtp");
properties.put("mail.smtp.host",server); // smtp.gmail.com?
//properties.put("mail.smtp.port", "25");
properties.put("mail.smtp.auth", "true");
Authenticator authenticator = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, pass);
}
};
Session session = Session.getDefaultInstance(properties, authenticator);
Message message =new MimeMessage(session);
message.setFrom(new InternetAddress("alert@test.com"));
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("alert1@test.com",false));
message.setSubject("test");
message.setText("hi");
Transport.send(message);
System.out.println("mail sernt");
我浏览了这些帖子,https://stackoverflow.com/questions/24688111/smtp-554-analysis,SMTP: Error 554, message is not RFC compliant, What does props.put("mail.smtp.host", host) in JavaMail do?所有这些似乎都暗示IP地址可能被阻止/与SMTP相关的东西。但是,我的邮件客户端工作正常。这是与SMTP配置有关还是我错过了什么。?
当我尝试调试时,我找到了文件未找到异常:jre1.6.0 \ lib \ javamail.providers和javamail.address.map。这与这些例外情况有关吗?另外,我如何检查防火墙是否不是问题。
答案 0 :(得分:0)
我收到了响应(错误554消息不符合标准)但是当我将邮件从格式更改为此时它停止了:
"<alert@test.com>"
如果有帮助,请试试。
答案 1 :(得分:0)
你能解决问题吗?我试过它没有任何例外,我几乎没有改变你的代码。如果有帮助,请看一下。
final String username = "myUserName"; //enter your user name
final String password = "myPassword"; //enter password
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", ""); //enter host name
props.put("mail.smtp.port", ""); //enter port no here
Session session = Session.getInstance(props,
new javax.mail.Authenticator(myUserName) {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(userName, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(userName));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("reciverMailAddress"));
message.setSubject("Test");
message.setText("This is the body of the email");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
答案 2 :(得分:0)
问题在于日期。消息&#34;消息不符合554标准是因为日期。添加
message.setSentDate(new Date());
解决了这个问题。