sendgrid-nodejs icon indicating copy to clipboard operation
sendgrid-nodejs copied to clipboard

Example on using inbound-mail-parser to parse incoming emails

Open machinshin opened this issue 6 years ago • 39 comments

Issue Summary

A summary of the issue and the environment in which it occurs. If suitable, include the steps required to reproduce the bug. Please feel free to include screenshots, screencasts, code examples.

I am unable to figure out how to use the @sendgrid/inbound-mail-parser package to parse inbound emails. need some example code

Steps to Reproduce

Setup a parse route in sendgrid (linked here: https://www.dropbox.com/s/cb6lwrmon9qwjzq/Screenshot%202017-10-12%2016.03.49.png?dl=0 ) this is the contents of an example email to the route in ngrok: https://gist.github.com/machinshin/e38cf7d20ec6319edcfda63ff7aca594

I have connected the parseroute to my webhook like so:

router.post('/api/email/parseroute', (req, res, next) => {
// have also tried:
router.post('/api/email/parseroute', bodyParser.raw(), (req, res, next) => {

    console.log(`-------------`)
    console.log(req.body)
    console.log(`-------------`)
    console.log(req.rawBody)
    console.log(`-------------`)

}

{}

undefined

As you can see, req.body is empty, and req.rawBody is 'undefined' Thus, I am not clear on how to get access to the raw email data, nor what to do with that data afterwards and how to instantiate the inbound-mail-parser

Any other information you want to share that is relevant to the issue being reported. Especially, why do you consider this to be a bug? What do you expect to happen instead?

Technical details:

  • sendgrid-nodejs Version: 6.1.4 (latest commit: 4c6d1cc )
  • Node.js Version: 4.1.2 "@sendgrid/inbound-mail-parser": "^6.1.4", "@sendgrid/mail": "^6.1.4",

machinshin avatar Oct 12 '17 23:10 machinshin