我正在尝试使用 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("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c9aee7bda6bbbda6bba889aaa6a7baaca5bda0e7a0bd" rel="noreferrer noopener nofollow">[email protected]</a>");
helper.setSubject(subj);
helper.setText(messageDefault + msg);
} catch (MessagingException e) {
log.error("ERRORE Invio email", e);
}
mailSender.send(message);
}
}
建议?
最佳答案
在我看来,输入的 Gaetano@ConseltiGT 地址无效,可能是因为拼写错误。我本以为它会是这样的:[email protected]或其他一些扩展名,以便域名能够真正得到解析。
关于java - com.sun.mail.smtp.SMTPAddressFailedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18057235/