Hello i keep getting this error after following a tutorial when trying to send SMTP emails using spring boot. Failed messages: javax.mail.MessagingException: can\'t de
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 theMimeMessageHelper
it is pretty easy to create aMimeMessage
:
// 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.