【问题标题】:SendGrid Email delivery status APISendGrid 电子邮件传递状态 API
【发布时间】:2020-01-17 15:18:53
【问题描述】:

我目前正在使用带有 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,如果可以,我应该怎么做?

谢谢

【问题讨论】:

    标签: node.js sendgrid sendgrid-api-v3


    【解决方案1】:

    我不确定您是否正在寻找这个,但他们有电子邮件活动 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/

    一些电子邮件活动:

    【讨论】:

    【解决方案2】:

    Sendgrid 具有 webhook,可以使用已交付或延迟等信息更新您的应用程序。这是一个链接 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/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多