awsses可以在localhost上工作,但不能在我的托管网站上工作

mspsb9vt  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(501)

因此,我在aws中使用route 53托管和运行我的网站-s3bucket(angular8作为fe)-elasticbean(java11/spring作为be)-rds(mysql)。
当应用程序在我的机器上运行时,我可以发送电子邮件->但是它们不会在ses控制台中显示为已发送,但是当运行我的网站时,不会发送电子邮件。
我已经在ses中验证了我的电子邮件地址。
我已经在ses中验证了我的网站。
这些是我的java应用程序的application.proprieties:

  1. # Email properties
  2. spring.mail.properties.mail.smtp.auth=true
  3. spring.mail.properties.mail.smtp.connectiontimeout=5000
  4. spring.mail.properties.mail.smtp.timeout=5000
  5. spring.mail.properties.mail.smtp.writetimeout=5000
  6. spring.mail.properties.mail.smtp.port=587
  7. spring.mail.properties.mail.smtp.starttls.enable=true
  8. spring.mail.properties.mail.smtp.starttls.required=true
  9. spring.mail.properties.mail.transport.protocol=smtp
  10. spring.mail.properties.mail.smtp.ssl.trust=*
  11. spring.mail.protocol = smtp
  12. spring.mail.debug = true;
  13. spring.mail.properties.mail.smtp.ssl.enable = true;
  14. spring.mail.properties.smtps.auth = true;
  15. # AWS CREDENTIALS
  16. spring.mail.host=email-smtp.eu-west-3.amazonaws.com
  17. spring.mail.port=587
  18. spring.mail.username=AKIA2QVYHK7ZQXAA6Y
  19. spring.mail.password=AAAAAAAAAAAAAA

电子邮件方法示例:

  1. // FEEDBACK MESSAGE
  2. @PostMapping("/email/feedback")
  3. public void sendFeedbackEmail(@RequestBody EmailStructure emailStructure) throws MessagingException, UnsupportedEncodingException {
  4. System.out.println("Sending feedback email...");
  5. Message msgToUser = new MimeMessage(getSession());
  6. Message msgToAdmin = new MimeMessage(getSession());
  7. msgToAdmin.setFrom(new InternetAddress("chittashop@gmail.com", "Chitta Bot"));
  8. msgToUser.setFrom(new InternetAddress("chittashop@gmail.com", "Chitta Shop"));
  9. // SEND THE MESSAGE TO YOURSELF
  10. msgToAdmin.addRecipient(Message.RecipientType.TO, new InternetAddress("chitta.shop@gmail.com"));
  11. msgToAdmin.setSubject("Feedback Message - " + emailStructure.getSubject());
  12. Multipart mpAdmin = new MimeMultipart();
  13. MimeBodyPart htmlPartAdmin = new MimeBodyPart();
  14. htmlPartAdmin.setContent("<div> Hi, <br> <br>You received a feedback message: <b>" + emailStructure.getSubject() +
  15. "</b>, from " + emailStructure.getEmail() + " with the following message: <br> <br> - <b> " + emailStructure.getMessage() +
  16. "</b> - <br> <br> <br>Thanks, <br> Chitta Shop Bot </div>", "text/html");
  17. mpAdmin.addBodyPart(htmlPartAdmin);
  18. msgToAdmin.setContent(mpAdmin);
  19. Transport.send(msgToAdmin);
  20. // SEND THE AUTOMATIC MESSAGE TO THE USER
  21. msgToUser.addRecipient(Message.RecipientType.TO, new InternetAddress(emailStructure.getEmail()));
  22. msgToUser.setSubject("Feedback Message");
  23. Multipart mpUser = new MimeMultipart();
  24. MimeBodyPart htmlPartUser = new MimeBodyPart();
  25. htmlPartUser.setContent("<div> Hi, <br> <br> <b>Thanks for the feedback! </b> " +
  26. "<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> " +
  27. "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>" +
  28. "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> " +
  29. "<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>" +
  30. " <br> <br> Thanks, <br> Chitta Shop </div>", "text/html");
  31. mpUser.addBodyPart(htmlPartUser);
  32. msgToUser.setContent(mpUser);
  33. Transport.send(msgToUser);
  34. }
km0tfn4u

km0tfn4u1#

你确定你的信用卡正在加载到你的托管网站上吗?这是我唯一能想到的问题。当我从ec2上的应用程序运行aws代码(如ses操作)时,我更喜欢使用:

  1. Region region = Region.US_WEST_2;
  2. SesClient client = SesClient.builder()
  3. .credentialsProvider(EnvironmentVariableCredentialsProvider.create())
  4. .region(region)
  5. .build();

如您所见,使用environmentvariablecredentialsprovider可以将creds设置为环境变量,并且从运行在ec2示例上的应用程序发送电子邮件没有问题。
您的ses服务客户机在您的代码中声明在哪里?

相关问题