Failed messages: javax.mail.MessagingException: can't determine local email address

*爱你&永不变心* 提交于 2019-11-28 11:35:45

The message says that a local email address is missing. It means that sender's email address or in other words an address that consumer can use to reply on your message. This address is a property of MimeMessage that you use with MimeMessageHelper, and you can use it to set the address

32.3 Using the JavaMail MimeMessageHelper

A class that comes in pretty handy when dealing with JavaMail messages is the org.springframework.mail.javamail.MimeMessageHelper class, which shields you from having to use the verbose JavaMail API. Using the MimeMessageHelper it is pretty easy to create a MimeMessage:

// of course you would use DI in any real-world cases
JavaMailSenderImpl sender = new JavaMailSenderImpl();
sender.setHost("mail.host.com");

MimeMessage message = sender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message);
helper.setFrom("your@email.address");
helper.setTo("test@host.com");
helper.setText("Thank you!");
sender.send(message);

This is the same code like on the doc page, but with addition of setFrom() which was missing only in this example.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!