通过SMTP使用AWS SES发送电子邮件,错误421

问题描述 投票:0回答:1

所以我通过SES购买了一个域名,我已经通过SES验证了。我通过使用workmail web app登录电子邮件测试了发送/接收工作。我在尝试使用我的spring应用程序发送电子邮件时收到以下错误。 javax.mail.MessagingException:无法连接到SMTP主机:email-smtp.eu-west-1.amazonaws.com,端口:25,响应:421

app config.Java

@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("[email protected]");
    mailSender.setPassword("mypassword");
    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;
}}


 EmailServiceImpl.java
 @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.setSubject(subject);
    message.setText(text);
    emailSender.send(message);
}
}   

EmailServiceImpl自动装入我的Web控制器,我在生成密码重置令牌后发送电子邮件

amazon-web-services spring-boot amazon-ses
1个回答
0
投票

您正在使用端口25. SES使用端口465或2465.还要记住使用SES SMTP凭据而不是您的IAM凭据(AccessKey)。

Connecting to the Amazon SES SMTP Endpoint

© www.soinside.com 2019 - 2024. All rights reserved.