java - AWS SES 在本地主机上工作,但在我的托管网站上不工作
问题描述
因此,我在 AWS 中使用 Route 53-S3Bucket(Angular8 作为 FE)-ElasticBean(Java11/Spring 作为 BE)-RDS(MySQL)托管和运行我的网站。
当应用程序在我的机器上运行时,我可以发送电子邮件 - > 但它们不会在 SES 控制台中显示为已发送,但在运行我的网站时,电子邮件未送达。
我已经在 SES 中验证了我的电子邮件地址。
我已经在 SES 中验证了我的网站。
这些是我的 Java 应用程序的 application.properties:
# 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 服务客户端在您的代码中声明的位置在哪里?
推荐阅读
- sql - Hive:根据年份和员工获得最小值?
- javascript - Next.js - 使用 router.push() 时禁用跳转到锚点
- c# - asp样板实现IEntityHistoryStore不工作
- android - 调用方法在对应的Item click In a RecyclerView
- .htaccess - 从 Htaccess 重定向 URL 中的 Tailing Dash
- wix - 如何使用 Wix 将文件安装到 D:驱动器(并检查 D:不是 CD ROM)
- flutter - 启动屏幕总是白色我的颤振应用程序启动
- python - PythonShell 在尝试在 heroku 中使用时给了我错误 EACCES spawn /app
- python - Python 计算已打开的 pdf 文件的页数
- java - 如何将实时数据从 java 代码流式传输到 excel?