我在给某个邮箱发送邮件时遇到了这个错误!
我不确定为什么需要验证一个不属于我的邮箱?
DEBUG SMTP:发送邮件时出现MessagingException异常,抛出: com.sun.mail.smtp.SMTPSendFailedException: 554 拒绝消息:电子邮件地址未经过验证。以下身份在EU-WEST-1地区未通过检查:danielhaughton@outlook.com
@Configuration
@PropertySource("app.properties")
@EnableTransactionManagement
public class AppConfig {
@Autowired
private Environment env;
@Bean
public JavaMailSender getJavaMailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("email-smtp.eu-west-1.amazonaws.com");
mailSender.setPort(25);
mailSender.setUsername("removedcreds");
mailSender.setPassword("removed creds");
Properties props = mailSender.getJavaMailProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
props.put("mail.debug", "true");
return mailSender;
}
邮件服务 @Component public class EmailServiceImpl {
@Autowired
public JavaMailSender emailSender;
public void sendSimpleMessage(String toAddress, String subject, String text)
{
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(toAddress);
message.setFrom("noreply@mydomain.com");
message.setSubject(subject);
message.setText(text);
emailSender.send(message);
}
}
我的emailserviceimpl被自动注入到一个web控制器中,我从中发送电子邮件。