如何解决AWS SES 可在本地主机上运行,但不能在我的托管网站上运行
所以我在 AWS 中托管并运行我的网站,使用 Route 53 - S3Bucket(Angular8 作为 FE)- ElasticBean(Java11/Spring 作为 BE)- RDS(MysqL)。
当应用在我的机器上运行时,我可以发送电子邮件 -> 但它们不会以发送的形式出现在 SES 控制台中,但在运行我的网站时,电子邮件不会发送。 >
我已经在 SES 中验证了我的电子邮件地址。
我已经在 SES 中验证了我的网站。
那些是我的 Java 应用程序的 application.proprieties:
# 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 服务客户端在您的代码中声明的位置在哪里?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。