我正在使用Spring Cloud AWS ses发送电子邮件。以下代码正在工作。我能够发送简单的电子邮件。
但是如何使用Spring Cloud AWS SES发送基于模板的电子邮件。
@Configuration
public class SimpleMailAutoConfig {
@Bean
public AmazonSimpleEmailService amazonSimpleEmailService(AWSCredentialsProvider credentialsProvider) {
return AmazonSimpleEmailServiceClientBuilder.standard()
.withCredentials(credentialsProvider)
.withRegion(Regions.US_EAST_1).build();
}
@Bean
public MailSender mailSender(AmazonSimpleEmailService ses) {
return new SimpleEmailServiceMailSender(ses);
}
}
@Service
public class MessageSendingService {
private MailSender mailSender;
@Autowired
public MessageSendingService(MailSender mailSender) {
this.mailSender = mailSender;
}
public void sendMailMessage() {
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setFrom("somefromemail@gmail.com");
simpleMailMessage.setTo("sometoemail@gmail.com");
simpleMailMessage.setSubject("test subject");
simpleMailMessage.setText("test content");
this.mailSender.send(simpleMailMessage);
}
}