我正尝试使用来自亚太地区(孟买)的aws ses java sdk发送电子邮件。 请参阅以下我尝试过的代码 AWSClientService(用于获取凭证,客户端,创建模板等)
App\User
使用此方法,我尝试从其他班级发送电子邮件
@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);
}
}
当我尝试执行此方法时,出现了异常
com.amazonaws.SdkClientException:无法执行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-south-1.amazonaws.com/13.126.245.211]失败:连接超时
可能是什么原因? 是因为我使用了亚太地区(孟买)吗? 如果是这样,我应该使用哪个区域? 由于我是印度人,我可以使用其他地区吗? 我是aws ses的初学者。请帮助我
答案 0 :(得分:0)
您的终端节点未在AWS区域和终端节点列表中列出。您确定要与真实端点连接吗?您是否检查过防火墙是否阻止了您?
参考:https://docs.aws.amazon.com/general/latest/gr/rande.html#ses_region
答案 1 :(得分:0)
我将区域更改为美国东部(弗吉尼亚北部),然后它起作用了。 确保防火墙未被阻止
答案 2 :(得分:0)
SES仅在3个地区可用。 us-east-1,eu-west-1和us-west-2 https://docs.aws.amazon.com/general/latest/gr/rande.html#ses_region