如何通过 SendGrid API v3 发送模板化电子邮件?
How to send templated email via SendGrid API v3?
在他们的文档中,SendGrid 描述了一个 structure 被发送到 API:
{ "to": // list of emails
"sub": // list of substitutions
"filters": // template ID here
}
但是具体应该如何与mail send结构一起使用呢?
{ "personalizations": 'to' and 'subject' here
"from": ...
"content": ... }
模板文档还说:
If you are using the Web API v3 mail send endpoint, you can specify which transactional template you would like to use simply by setting the template ID in the template_id parameter of your JSON payload.
"Simply"。好的。但是我的替代品将如何指定呢?
好吧,下面是一个工作示例。这与 v3 文档不同。
{
"personalizations" : [ {
"substitutions" : {
":name" : "John"
},
"subject" : "Hello from Java",
"to" : [ {
"email" : "john@example.com"
} ]
} ],
"from" : {
"email" : "john@example.com"
},
"template_id" : "11111111-1111-1111-1111-111111111111"
}
在他们的文档中,SendGrid 描述了一个 structure 被发送到 API:
{ "to": // list of emails
"sub": // list of substitutions
"filters": // template ID here
}
但是具体应该如何与mail send结构一起使用呢?
{ "personalizations": 'to' and 'subject' here
"from": ...
"content": ... }
模板文档还说:
If you are using the Web API v3 mail send endpoint, you can specify which transactional template you would like to use simply by setting the template ID in the template_id parameter of your JSON payload.
"Simply"。好的。但是我的替代品将如何指定呢?
好吧,下面是一个工作示例。这与 v3 文档不同。
{
"personalizations" : [ {
"substitutions" : {
":name" : "John"
},
"subject" : "Hello from Java",
"to" : [ {
"email" : "john@example.com"
} ]
} ],
"from" : {
"email" : "john@example.com"
},
"template_id" : "11111111-1111-1111-1111-111111111111"
}