只有当我尝试使用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:错误554,消息不符合RFC,props.put("mail.smtp.host",host)在JavaMail中做什么?所有这些似乎都表明IP地址可能被阻止/与SMTP有关。然而,我的邮件客户端运行良好。这与SMTP配置有关吗?或者我遗漏了什么。?
当我尝试调试时,我得到了jre1.6.0\lib\javamail.providers和javamail.address.map的未找到文件异常。这与这些异常有关吗。此外,我如何检查我的防火墙是否不是问题所在。
我得到了响应(错误554消息不符合标准),但当我将邮件格式从更改为以下格式时,它停止了
"<alert@test.com>"
如果有帮助,请尝试。
你能解决这个问题吗?我试过了,它没有给出任何异常,我几乎没有改变你的代码。如果对你有帮助,请看一看。
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);
}
}
问题出在日期上。消息"消息不符合554标准是由于日期原因。正在添加
message.setSentDate(new Date());
修复了问题。
此SMTP:错误554,消息不符合RFC帮助。