首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用aws Send (Java)从亚太地区(孟买)发送电子邮件

使用aws Send (Java)从亚太地区(孟买)发送电子邮件
EN

Stack Overflow用户
提问于 2019-03-22 06:22:44
回答 3查看 953关注 0票数 0

我试图用aws从亚太地区(孟买)发送电子邮件。请参阅下面我尝试过的AWSClientService代码(获取凭据、客户端、创建模板等)。

代码语言:javascript
复制
@Service
public class AWSClientServiceImpl implements AWSClientService {

@Value("${aws.ses.accesKey}")
private String accessKey;

@Value("${aws.ses.secretKey}")
private String secretKey;

@Override
public AWSCredentialsProvider getAWSCredentials(){
    BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey,secretKey);
    return new AWSStaticCredentialsProvider(credentials);
}

@Override
public AmazonSimpleEmailService getAmazonSESClient(){
    return AmazonSimpleEmailServiceClientBuilder.standard()
            .withCredentials(getAWSCredentials())
            .withRegion(Regions.AP_SOUTH_1).build();
}

@Override
public VerifyEmailIdentityResult verifyEmailIdentity(AmazonSimpleEmailService client, String emailAddress){
    VerifyEmailIdentityRequest emailIdentityRequest = new VerifyEmailIdentityRequest().withEmailAddress(emailAddress);
    return client.verifyEmailIdentity(emailIdentityRequest);
}

@Override
public CreateTemplateResult createTemplate(AmazonSimpleEmailService amazonSES, String templateName, String subjectPart, String htmlPart) {
    Template template = new Template();
    template.setTemplateName(templateName);
    template.setSubjectPart(subjectPart);
    template.setHtmlPart(htmlPart);
    CreateTemplateRequest createTemplateRequest = new CreateTemplateRequest();
    createTemplateRequest.setTemplate(template);
    return amazonSES.createTemplate(createTemplateRequest);
}
}

使用这个,我尝试从另一个类发送电子邮件。

代码语言:javascript
复制
public void sendSimpleSESMessage(){
    final String FROM = "test@sample.com";
    final String TO = "test@sample.com";
    final String SUBJECT = "Amazon SES test (AWS SDK for Java)";
    final String HTMLBODY = "<h1>Amazon SES test (AWS SDK for Java)</h1>"
            + "<p>This email was sent with <a href='https://aws.amazon.com/ses/'>"
            + "Amazon SES</a> using the <a href='https://aws.amazon.com/sdk-for-java/'>"
            + "AWS SDK for Java</a>";
    final String TEXTBODY = "This email was sent through Amazon SES "
            + "using the AWS SDK for Java.";
    try {
        AmazonSimpleEmailService client = awsClientService.getAmazonSESClient();
        log.info("Email Verification for " + FROM + " started");
        VerifyEmailIdentityResult verifyEmailIdentityResult = awsClientService.verifyEmailIdentity(client, FROM);
        log.info("Email verification for " + FROM + " completed");
        SendEmailRequest request = new SendEmailRequest()
                .withDestination(
                        new Destination().withToAddresses(TO))
                .withMessage(new com.amazonaws.services.simpleemail.model.Message()
                        .withBody(new Body()
                                .withHtml(new Content()
                                        .withCharset("UTF-8").withData(HTMLBODY))
                                .withText(new Content()
                                        .withCharset("UTF-8").withData(TEXTBODY)))
                        .withSubject(new Content()
                                .withCharset("UTF-8").withData(SUBJECT)))
                .withSource(FROM);
        client.sendEmail(request);
        log.info("Email was sent from "+FROM+" to "+TO);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

当我尝试执行这个方法时,我得到了一个异常。

无法执行HTTP请求:连接到email.ap-south-1.amazonaws.com:443 email.ap-south-1.amazonaws.com/13.126.113.212,email.ap-south-1.amazonaws.com/35.154.131.193,电子邮件.email.ap 1.amazonaws.com/13.126.245.211失败:连接超时

原因可能是什么?是因为我使用了亚太地区(孟买)吗?如果是,我应该使用哪个区域?因为我是印度人,我可以使用其他地区吗?我是aws的初学者。请帮帮我

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-03-22 10:43:50

我把这个地区改成了美国东部(北弗吉尼亚),然后起了作用。确保防火墙不被阻塞。

票数 0
EN

Stack Overflow用户

发布于 2019-03-22 07:09:18

您的端点没有在AWS区域和端点列表中列出。您确定您正在与真正的端点连接吗?您是否检查了防火墙是否阻止了您?

参考文献:region

票数 0
EN

Stack Overflow用户

发布于 2019-03-27 17:24:36

SES只在3个区域提供。美国-东-1,欧盟-西-1和美国-西-2 region

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55293964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档