我正在尝试使用Spring生成并发送自动邮件。

尝试发送电子邮件时出现此异常:

org.springframework.mail.MailSendException: Failed messages: javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 550 5.1.8 <Gaetano@ConseltiGT>: Sender address rejected: Domain not found
; message exception details (1) are:
Failed message 1:
javax.mail.SendFailedException: Invalid Addresses;


在application-context.xml文件中,我具有:

    <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"
    p:host="${email.account.host}" p:port="${email.account.port}"
    p:username="${email.account.username}" p:password="${email.account.password}"
    p:javaMailProperties-ref="javaMailProperties"/>

<util:properties id="javaMailProperties">
    <prop key="mail.smtp.auth">${email.account.smtp.auth}</prop>
    <prop key="mail.smtp.starttls.enable">${email.account.smtp.starttls.enable}</prop>
</util:properties>


在服务范围内,我有:

  @Service
  @Slf4j
  public class EmailSenderTUService {

@Autowired
private JavaMailSender mailSender;

private String messageDefault = "Il sistema TESORERIA UNICA TELEMATICA richiede attenzione\n";


public void sendMail(String subj, String msg) {
    MimeMessage message = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message);
    try {
        helper.setTo("[email protected]");
        helper.setSubject(subj);
        helper.setText(messageDefault + msg);
    } catch (MessagingException e) {
        log.error("ERRORE Invio email", e);
    }
    mailSender.send(message);
}

}


有什么建议吗?

最佳答案

在我看来,输入的Gaetano @ ConseltiGT地址无效,可能是因为输入错误。我希望它是这样的:Gaetano@ConseltiGT.​​com或其他扩展名,以便实际上可以解析该域。

10-07 13:06