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

后端 未结 1 790
长情又很酷
长情又很酷 2020-12-10 20:00

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

1条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-10 20:40

    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.

    0 讨论(0)
提交回复
热议问题