Tom Coomer
Tom Coomer

Reputation: 6527

SendGrid Email delivery status API

I am current using the SendGrid email API with Node.js to send an email using their sample code on GitHub.

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
  to: '[email protected]',
  from: '[email protected]',
  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);

I would like to be able to show the delivery status of this email in my app. Is this possible using the SendGrid API and if so, how should I do this?

Thank you

Upvotes: 4

Views: 7889

Answers (2)

Lys
Lys

Reputation: 825

Sendgrid has webhooks, that can update your app with information like delivered or deferred etc. here is a link https://sendgrid.com/docs/for-developers/tracking-events/getting-started-event-webhook/ and look here too for different responses that sendgrid can send you https://sendgrid.com/docs/for-developers/tracking-events/getting-started-event-webhook/

Upvotes: 2

Sandeep Patel
Sandeep Patel

Reputation: 5148

I am not sure if you are looking for this, But they have email activity API which you have to subscribe separately. 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();

Also, check this for compund query: https://sendgrid.com/docs/for-developers/sending-email/getting-started-email-activity-api/

Some of email activity : enter image description here

Upvotes: 4

Related Questions