javamail 异常
我用javamail向.@sina.cn 或者 @qq.com发送邮件失败。只能给本公司邮件服务器中的邮箱发送邮件。请问这是为什么?
异常信息:
javax.mail.SendFailedException: Invalid Addresses; nested exception is: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <yangbo343567562@sina.cn>: Relay access denied ; nested exception is: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <lovesmellysmelly@qq.com>: Relay access denied ; nested exception is: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <lovesmellysmelly@qq.com>: Relay access denied at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1196) at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:584) at javax.mail.Transport.send0(Transport.java:169) at javax.mail.Transport.send(Transport.java:98) at test.SendMailTest.sendMail(SendMailTest.java:70) at test.SendMailTest.main(SendMailTest.java:117) Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <yangbo343567562@sina.cn>: Relay access denied ; nested exception is: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <lovesmellysmelly@qq.com>: Relay access denied 发送邮件失败 at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1094) ... 5 more Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <lovesmellysmelly@qq.com>: Relay access denied ... 6 more
public boolean sendMail() { Properties propers = new Properties(); propers.put("mail.smtp.host", host); propers.put("mail.smtp.auth", "true"); // propers.setProperty("mail.smtp.socketFactory.fallback", "false"); // propers.setProperty("mail.smtp.port", "25"); // propers.setProperty("mail.smtp.socketFactory.port", "25"); Session session = Session.getDefaultInstance(propers,new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); Message message = new MimeMessage(session); try { message.setText(content); message.setFrom(new InternetAddress(username, parName)); message.setSubject(subject); Address[] addressesTo = new InternetAddress[to.length]; for (int i = 0; i < to.length; i++) { addressesTo[i] = new InternetAddress(to[i]); } message.addRecipients(Message.RecipientType.TO, addressesTo); // InternetAddress[] addressCc = new InternetAddress[cc.length]; // for (int i = 0; i < cc.length; i++) { // addressCc[i] = new InternetAddress(cc[i]); // } // message.addRecipients(Message.RecipientType.CC, addressCc); message.setContent(content,"text/html;charset=GBK"); message.saveChanges(); Transport.send(message); System.out.println("send mail ok!"); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
String host ="smtp.gdyilian.com"; String username = "payreporter@payeco.com"; String password = "4489a6"; // private String name = "yangbo"; // private String value = "343567562"; // private String to[] = {"yang.bo@payeco.com"}; private String to[] = { "yangbo343567562@sina.cn", "lovesmellysmelly@qq.com", "yang.bo@payeco.com" };// 收件人 private String cc[] = {"lovesmellysmelly@qq.com" }; // private String cc[] = { "yangbo343567562@sina.cn", // "lovesmellysmelly@qq.com", "yang.bo@payeco.com" };// 抄送人; private String from = "yangbo343567562@sina.cn"; private String subject = "YANGBO"; private String content = "this is the Test javamail"; private String parName = "system";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
楼主解决了吗? ,我本地测试没问题,上生产就不行了
楼主怎么解决的呢?我遇到一样的问题。换成gmail 发送,端口Ping 不通
回复
而且异常提示很明显三SMTP的问题啊 Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <yangbo343567562@sina.cn>: Relay access denied
@breaking foxmail客户端可以发出去,用javamail的代码客户端发送就报错了。请问我的java代码配置少了什么?
回复
http://www.symantec.com/business/support/index?page=content&id=TECH169847 好吧,我英文不太好,这个你参考下吧
回复
这个是服务器的配置啊。用foxmail能发出去,用java才不能发出去。这不应该是服务器的问题。应该是java代码问题吧!
回复
这个还是是配置问题,但不是服务器配置问题。还是我的java代码配置问题。还是非常感谢你的回答。
SMTPAddressFailedException
SMTP服务器配置的问题?