次のメール送信を実装しました。
Template template = freemarkerConfig.getTemplate(templateFileName);
String html = FreeMarkerTemplateUtils.processTemplateIntoString(template, props);
logger.debug("Send email to {} with subject: [{}]", Arrays.toString(to), subject);
Personalization personalization = new Personalization();
for (String toEmail : to) {
personalization.addTo(new Email(toEmail));
}
Mail mail = new Mail();
mail.addPersonalization(personalization);
mail.setSubject(subject);
mail.setFrom(new Email(from));
mail.addContent(new Content("text/html", html));
Request request = new Request();
try {
request.setMethod(Method.POST);
request.setEndpoint("mail/send");
request.setBody(mail.build());
Response response = this.sendGrid.api(request);
logger.info("Response:{}", response);
} catch (IOException ex) {
logger.error("Exception occurred during email sending", ex);
}
SMTP-over-SSL
、またはを使用する必要がある要件がありますSMTP+STARTTLS
。
私はそれが何を意味するのか分かりません。この場合、(web api の代わりに) smtp api を使用する必要がありますか? ただし、sendgrid の公式サイトでは、Web API を使用することを推奨しています。