Sendgrid-nodejs: How to get messageId from header

Created on 12 Mar 2019  ·  4Comments  ·  Source: sendgrid/sendgrid-nodejs

We’re using inbound parse to handle messages inside SendGrid. Now we want to work with replying to messages, for which we need to extract the Message-ID from the email.

How do we extract the Message-ID from an email that goes via the inbound parsing? As I do not see it in the request headers.

unknown or a waiting for feedback question

Most helpful comment

@wooyah

I found it better to use the following...

  var MailParser = require("mailparser").MailParser;
  var mailparser = new MailParser();
  mailparser.on("end", function(mail_object){
      log(util.inspect(mail_object));     
  });
  mailparser.write(req.body.email);
  mailparser.end();

This requires checking the Inbound Parse setting 'POST the raw, full MIME message'.
You'll find the mail_object has what you need.

All 4 comments

Hello @wooyah,

The Message-ID should be in the headers. Could you please provide a bit more detail so I can try and reproduce?

  1. Could you provide a code sample?
  2. Are you using this SDK?

With Best Regards,

Elmer

@wooyah

I found it better to use the following...

  var MailParser = require("mailparser").MailParser;
  var mailparser = new MailParser();
  mailparser.on("end", function(mail_object){
      log(util.inspect(mail_object));     
  });
  mailparser.write(req.body.email);
  mailparser.end();

This requires checking the Inbound Parse setting 'POST the raw, full MIME message'.
You'll find the mail_object has what you need.

Thanks for helping out @jerryongit!

I've just edited your comment for readability.

Thanks @jerryongit ,
Your code was really helpful.
I set to use busboy to catch required data from Headers, and now have no problem to get. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

prasoonjalan picture prasoonjalan  ·  3Comments

thinkingserious picture thinkingserious  ·  4Comments

kiranshashiny picture kiranshashiny  ·  4Comments

thidasapankaja picture thidasapankaja  ·  4Comments

mikemaccana picture mikemaccana  ·  4Comments