所以我在AWS中的网站使用Route 53-S3Bucket(Angular8作为FE(-ElasticBean(Java11/Spring作为BE(-RDS(MySQL(托管和运行。
当应用程序在我的机器上运行时,我可以发送电子邮件->但它们不会在发送时显示在SES控制台中,但当运行我的网站时,电子邮件不会发送
我已经在SES中验证了我的电子邮件地址
我已经在SES中验证了我的网站
这些是我的Java应用程序的应用程序:
# Email properties
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=5000
spring.mail.properties.mail.smtp.writetimeout=5000
spring.mail.properties.mail.smtp.port=587
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.transport.protocol=smtp
spring.mail.properties.mail.smtp.ssl.trust=*
spring.mail.protocol = smtp
spring.mail.debug = true;
spring.mail.properties.mail.smtp.ssl.enable = true;
spring.mail.properties.smtps.auth = true;
# AWS CREDENTIALS
spring.mail.host=email-smtp.eu-west-3.amazonaws.com
spring.mail.port=587
spring.mail.username=AKIA2QVYHK7ZQXAA6Y
spring.mail.password=AAAAAAAAAAAAAA
电子邮件方法示例:
// FEEDBACK MESSAGE
@PostMapping("/email/feedback")
public void sendFeedbackEmail(@RequestBody EmailStructure emailStructure) throws MessagingException, UnsupportedEncodingException {
System.out.println("Sending feedback email...");
Message msgToUser = new MimeMessage(getSession());
Message msgToAdmin = new MimeMessage(getSession());
msgToAdmin.setFrom(new InternetAddress("chittashop@gmail.com", "Chitta Bot"));
msgToUser.setFrom(new InternetAddress("chittashop@gmail.com", "Chitta Shop"));
// SEND THE MESSAGE TO YOURSELF
msgToAdmin.addRecipient(Message.RecipientType.TO, new InternetAddress("chitta.shop@gmail.com"));
msgToAdmin.setSubject("Feedback Message - " + emailStructure.getSubject());
Multipart mpAdmin = new MimeMultipart();
MimeBodyPart htmlPartAdmin = new MimeBodyPart();
htmlPartAdmin.setContent("<div> Hi, <br> <br>You received a feedback message: <b>" + emailStructure.getSubject() +
"</b>, from " + emailStructure.getEmail() + " with the following message: <br> <br> - <b> " + emailStructure.getMessage() +
"</b> - <br> <br> <br>Thanks, <br> Chitta Shop Bot </div>", "text/html");
mpAdmin.addBodyPart(htmlPartAdmin);
msgToAdmin.setContent(mpAdmin);
Transport.send(msgToAdmin);
// SEND THE AUTOMATIC MESSAGE TO THE USER
msgToUser.addRecipient(Message.RecipientType.TO, new InternetAddress(emailStructure.getEmail()));
msgToUser.setSubject("Feedback Message");
Multipart mpUser = new MimeMultipart();
MimeBodyPart htmlPartUser = new MimeBodyPart();
htmlPartUser.setContent("<div> Hi, <br> <br> <b>Thanks for the feedback! </b> " +
"<br> <br> This automatic reply is just to let you know that we received your feedback message and we will get back to you with a response as quickly as possible. <br> " +
"During 9:00 a.m to 18:30 p.m (GMT) we do our best to reply as quick as we can, usually within a couple of hours. Evenings and weekends may take us a little bit longer. <br> <br>" +
"If you have a general question about a specific product, you are welcome to browse our FAQ page for more details of all of our features and answers to frequently asked questions. <br> " +
"<br>If you have any additional information that you think will help us to assist you, please feel free to reply to this email. <br> <br> <b> We look forward to chatting soon! </b>" +
" <br> <br> Thanks, <br> Chitta Shop </div>", "text/html");
mpUser.addBodyPart(htmlPartUser);
msgToUser.setContent(mpUser);
Transport.send(msgToUser);
}
你确定你的信任正在你的托管网站上加载吗?这是我唯一能想到的问题。当我从EC2上的应用程序运行AWS代码时,比如SES操作,我更喜欢使用:
Region region = Region.US_WEST_2;
SesClient client = SesClient.builder()
.credentialsProvider(EnvironmentVariableCredentialsProvider.create())
.region(region)
.build();
正如您所看到的,使用EnvironmentVariableCredentialsProvider可以将信用设置为环境变量,并且从运行在EC2实例上的应用程序发送电子邮件没有问题。
您的SES服务客户端在代码中声明在哪里?