0

我正在尝试在 cURL 中构建一个 API,以分别向超过 100,000 多个收件人发送电子邮件 (即看起来应该是我亲自将邮件发送给他的)。我还将使用一个动态模板,它有 3 个参数可以传递 - first_name, date, & city。我应该如何在 cURL 中为上述想法构建 API?我是 API 和 cURL 的初学者 - 这就是为什么我有点困惑

另外,我尝试使用下面的代码(参考),但我不确定我应该把我的 // 参数放在哪里first_name-citydate也能指导我吗?

curl --request POST \
  --url https://api.sendgrid.com/v3/mail/send \
  --header 'authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{"personalizations": [{"to": [{"email": "recipient@example.com"}]}],"from": {"email": "sendeexampexample@example.com"},"subject":"Hello, World!","content": [{"type": "text/plain","value": "Heya!"}], "template_id" : "YOUR_TEMPLATE_ID"}'

我发现单个 API 调用只能支持 1000 个收件人 - 所以为了覆盖 100,000 人,我会进行 100 次这样的 API 调用(每个调用 1000 个收件人)。

4

1 回答 1

1

Twilio SendGrid 开发人员布道者在这里。

当您发送模板数据时,您需要将其作为个性化数组的一部分连同相关的电子邮件地址一起发送到 key 下dynamic_template_data。例如:

curl --request POST \
  --url https://api.sendgrid.com/v3/mail/send \
  --header 'authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "personalizations": [
    {
      "to": [{"email": "recipient@example.com"}],
      "dynamic_template_data": { "first_name": "Phil" }
    }
  ],
  "from": {"email": "sendeexampexample@example.com"},
  "subject":"Hello, World!",
  "content": [{"type": "text/plain","value": "Heya!"}],
  "template_id" : "YOUR_TEMPLATE_ID"
}'

(为便于阅读,上面添加了换行符。)

查看有关使用动态模板数据发送电子邮件的此文档以获取更多信息。

于 2021-10-18T22:51:07.437 回答