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

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

因此,我在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);
    }
km0tfn4u

km0tfn4u1#

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

Region region = Region.US_WEST_2;
SesClient client = SesClient.builder()
                      .credentialsProvider(EnvironmentVariableCredentialsProvider.create())
                      .region(region)
                      .build();

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

相关问题