SendGrid 电子邮件传送状态 API

SendGrid Email delivery status API

我目前正在使用带有 Node.js 的 SendGrid 电子邮件 API 发送电子邮件,使用他们在 GitHub.

上的示例代码
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
  to: 'test@example.com',
  from: 'test@example.com',
  subject: 'Sending with Twilio SendGrid is Fun',
  text: 'and easy to do anywhere, even with Node.js',
  html: '<strong>and easy to do anywhere, even with Node.js</strong>',
};
sgMail.send(msg);

我希望能够在我的应用程序中显示这封电子邮件的发送状态。 这可以使用 SendGrid API 吗?如果可以,我应该怎么做?

谢谢

我不确定您是否正在寻找这个,但是他们有电子邮件 activity API,您必须单独订阅。 email activity

var http = require("https");

var options = {
  "method": "GET",
  "hostname": "api.sendgrid.com",
  "port": null,
  "path": "/v3/messages?query=status="processed" AND to_email="<<email>>"",
  "headers": {
    "authorization": "Bearer <<YOUR_API_KEY_HERE>>"
  }
};

    var req = http.request(options, function (res) {
      var chunks = [];

      res.on("data", function (chunk) {
        chunks.push(chunk);
      });

      res.on("end", function () {
        var body = Buffer.concat(chunks);
        console.log(body.toString());
      });
    });

    req.write("{}");
    req.end();

此外,检查复合查询: https://sendgrid.com/docs/for-developers/sending-email/getting-started-email-activity-api/

部分电子邮件 activity :

Sendgrid 有 webhooks,可以使用交付或延迟等信息更新您的应用程序。这里是 link https://sendgrid.com/docs/for-developers/tracking-events/getting-started-event-webhook/ 也可以在这里查看 sendgrid 可以发送给您的不同回复 https://sendgrid.com/docs/for-developers/tracking-events/getting-started-event-webhook/