Java AWS SES在本地主机上工作,但在我托管的网站上不工作
因此,我在AWS中使用Route 53-S3Bucket(Angular8作为FE)、ElasticBean(Java11/Spring作为BE)、RDS(MySQL)托管和运行我的网站 当应用程序在我的机器上运行时,我可以发送电子邮件->但它们不会在SES控制台中显示为已发送,但当运行我的网站时,电子邮件不会发送。 我已经在SES中验证了我的电子邮件地址。 我已经在SES中验证了我的网站。 这些是我的Java应用程序的application.properties:Java AWS SES在本地主机上工作,但在我托管的网站上不工作,java,spring,amazon-web-services,email,amazon-ses,Java,Spring,Amazon Web Services,Email,Amazon Ses,因此,我在AWS中使用Route 53-S3Bucket(Angular8作为FE)、ElasticBean(Java11/Spring作为BE)、RDS(MySQL)托管和运行我的网站 当应用程序在我的机器上运行时,我可以发送电子邮件->但它们不会在SES控制台中显示为已发送,但当运行我的网站时,电子邮件不会发送。 我已经在SES中验证了我的电子邮件地址。 我已经在SES中验证了我的网站。 这些是我的Java应用程序的application.properties: # Email proper
# 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);
}
//反馈消息
@邮递(“/电子邮件/反馈”)
public void sendFeedbackEmail(@RequestBody-EmailStructure-EmailStructure)引发MessaginException,UnsupportedEncodingException{
System.out.println(“发送反馈电子邮件…”);
Message msgToUser=new mimessage(getSession());
Message msgToAdmin=new mimessage(getSession());
msgToAdmin.setFrom(新的InternetAddress(“chittashop@gmail.com","Chitta Bot"),;
msgToUser.setFrom(新的Internet地址(“chittashop@gmail.com","奇塔店"),;
//把信息传给你自己
msgToAdmin.addRecipient(Message.RecipientType.TO,新的InternetAddress(“chitta。shop@gmail.com"));
msgToAdmin.setSubject(“反馈消息-”+emailStructure.getSubject());
Multipart mpAdmin=新的MimeMultipart();
MimeBodyPart htmlPartAdmin=新的MimeBodyPart();
htmlPartAdmin.setContent(“您好,
您收到了一条反馈消息:“+emailStructure.getSubject()+
,来自“+emailStructure.getEmail()+”并显示以下消息:
-“+emailStructure.getMessage()+
“-
谢谢,
奇塔商店机器人”,“text/html”);
mpAdmin.addBodyPart(htmlPartAdmin);
msgToAdmin.setContent(mpAdmin);
发送(msgToAdmin);
//将自动消息发送给用户
msgToUser.addRecipient(Message.RecipientType.TO,新的InternetAddress(emailStructure.getEmail());
msgToUser.setSubject(“反馈消息”);
Multipart mpUser=新的MimeMultipart();
MimeBodyPart htmlPartUser=新的MimeBodyPart();
setContent(“您好,
谢谢您的反馈!”+
“
此自动回复只是让您知道我们已收到您的反馈信息,我们将尽快回复您。
”+
“在上午9:00至下午18:30(格林尼治标准时间)期间,我们尽最大努力尽快回复,通常在几个小时内。晚上和周末可能需要更长的时间。”+
“如果您对特定产品有一般性问题,欢迎您浏览我们的常见问题解答页面,了解我们所有功能的详细信息以及常见问题解答。
”+
“
如果您有任何您认为有助于我们帮助您的其他信息,请随时回复此电子邮件。
我们期待不久的聊天!”+
“
谢谢,
奇塔商店”,“text/html”);
mpUser.addBodyPart(htmlPartUser);
msgToUser.setContent(mpUser);
传输发送(msgToUser);
}
您确定您的托管站点上正在加载creds吗?这是我能想到的唯一问题。当我从EC2上的应用程序(如SES操作)运行AWS代码时,我更喜欢使用:
Region region = Region.US_WEST_2;
SesClient client = SesClient.builder()
.credentialsProvider(EnvironmentVariableCredentialsProvider.create())
.region(region)
.build();
如您所见,使用环境变量CredentialsProvider可以将Cred设置为环境变量,并且从EC2实例上运行的应用发送电子邮件时不会出现问题
在您的代码中,您的SES服务客户端在哪里声明?老实说,我没有声明任何SES服务,因为从我在您的区域中使用AWS凭据时收集的信息来看,您可以直接使用JavaMail库。我错了吗?好的,我想我找到了。我在电子邮件服务中运行了一个特定的配置,它覆盖了AWS配置。使用SES时,最好在代码中使用服务客户端。我们这里有一个SESV2SpringBoot应用程序示例-谢谢大家,虽然解决方案很简单,但我并不是一个人找到的。你帮了我!非常感谢!