[英]Sending HTML email through amazon ses
我正在使用亚马逊ses发送批量电子邮件。 我的代码如下
public void sendMail(String sender, LinkedList<String> recipients, String subject, String body) {
Destination destination = new Destination(recipients);
try {
ACCESS_KEY = EmailSender.prop.getProperty("accessKey");
SECRET_KEY = EmailSender.prop.getProperty("secretKey");
Content subjectContent = new Content(subject);
Content bodyContent = new Content(body);
Body msgBody = new Body(bodyContent);
Message msg = new Message(subjectContent, msgBody);
SendEmailRequest request = new SendEmailRequest(sender, destination, msg);
AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
AmazonSimpleEmailServiceClient sesClient = new AmazonSimpleEmailServiceClient(credentials);
SendEmailResult result = sesClient.sendEmail(request);
System.out.println(result + "Email sent");
}catch(Exception e) {
System.out.println("Exception from EmailSender.java. Email not send");
}
在这里,我将我的html内容作为变量“ body ”的字符串给出。
邮件发送成功。 但我把html内容作为电子邮件。 如何在邮件中发送html内容。 代码中的哪些更改将解决此问题?
来自Amazon SES开发者指南 :
您应该使用WithHtml方法:
Content subjContent = new Content().withData("Test of Amazon SES");
Message msg = new Message().withSubject(subjContent);
// Include a body in both text and HTML formats
Content textContent = new Content().withData("Hello - I hope you're having a good day.");
Content htmlContent = new Content().withData("<h1>Hello - I hope you're having a good day.</h1>");
Body body = new Body().withHtml(htmlContent).withText(textContent);
msg.setBody(body);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.