我试图用aws从亚太地区(孟买)发送电子邮件。请参阅下面我尝试过的AWSClientService代码(获取凭据、客户端、创建模板等)。
@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);
}
}使用这个,我尝试从另一个类发送电子邮件。
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的初学者。请帮帮我
https://stackoverflow.com/questions/55293964
复制相似问题