【发布时间】:2016-12-20 12:18:04
【问题描述】:
我创建了一个 sendgrid 模板,以便能够根据用户的信息构建我的电子邮件。到目前为止,它真的很简单:
<html>
<body>
<div><%body%></div>
<div>Hi there :username!</div>
<div>Please, click on here to complete Accoung Activation: :activation</div>
<div>Please, bear with us.</div>
</body>
</html>
据我所知,我可以替换令牌(:username 和 :activation)。
不过,我不太明白如何在 java 上构建它。到目前为止,我已经能够编写这段代码来发送带有模板的电子邮件:
String activationUri = "http://activation uri.sample.com/activation";
String address = "sample@sample.com";
Email from = new Email("no-reply@facetz.zone");
String subject = "Account activation mail request";
Email to = new Email(address);
Content content = new Content("text/plain", activationUri);
Mail mail = new Mail(from, subject, to, content);
mail.setTemplateId("7928c2b2-c5a9-4918-a035-db5b7aae532b");
SendGrid sg = new SendGrid("api_key");
Request request = new Request();
try {
request.method = Method.POST;
request.endpoint = "mail/send";
request.body = mail.build();
Response response = sg.api(request);
} catch (IOException ex) {
throw MailGenerationException.create(address, ex);
}
如您所见,我已经设置了templateId,但是,我不知道如何:
- 设置模板版本。
- 添加令牌替换。
另一方面:
-
section tags和substitution tags和<%subject%>和<%body%>标签之间有什么区别?
拜托,我真的看过文档。到目前为止,我还无法理解我提出的所有内容。
【问题讨论】:
-
这里也有一些例子:sendgrid-java