sendgrid。 SMTP-over-SSL或SMTP + STARTTLS

时间:2018-01-27 16:10:21

标签: java email ssl sendgrid sendgrid-api-v3

我已实施以下电子邮件发送:

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-SSLSMTP+STARTTLS

我不确定这是什么意思。在这种情况下我应该使用smtp api(而不是web api)吗?但sendgrid官方网站建议使用web api。

1 个答案:

答案 0 :(得分:0)

如果您只关心通过TLS将发送到 Sendgrid,请确保启动它并正确运行连接,然后将其加密发送。

如果您需要确保所有邮件仅通过TLS发送出SendGrid,您可以Enforce TLS作为邮件发送的选项。 SendGrid始终尝试TLS连接出站,但如果未设置该标志,则将恢复为未加密。