How to send templated email via SendGrid API v3?

时间:2017-12-18 08:09:41

标签: sendgrid sendgrid-api-v3 sendgrid-templates

In their docs SendGrid describes a structure to be sent to API:

MessageId Bits: [1111 1111 1101 1101], Value: [65501].
MessageSize Bits: [1111 1111 1101 1101], Value: [65501].

But how exactly should it be used together with the mail send structure?

{ "to": // list of emails
  "sub": // list of substitutions
  "filters": // template ID here
}

Also the template doc says:

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". Ok. But how my substitutuins gonna be specified then?

1 个答案:

答案 0 :(得分:0)

嗯,下面是一个有效的例子。这与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"
}