A Node.js / Express.js app using SendGrid's Inbound Parse to parse email data / attachments.
-
Log into your SendGrid account
-
Go to Settings > Inbound Parse
-
Click
Add Host & URL
- Select a verified domain
- Add a sub-domain
parse
(This will narrow down the parsed email to this sub-domain) - Add a
Destination URL
(This has to be publicly available) - Check
Check incoming emails for spam
(This will return aspam_score
andspam_report
) - Leave
POST the raw, full MIME message
unchecked
-
Log into you domain registrar
-
Add an MX record
- Host
parse
- TTL
10m
- Mail Server
mx.sendgrid.net
- Host
For development you can use
https://ngrok.com/
or just to testhttps://webhook.site/
npm install
npm start
You can now test the Inbound Parse by sending an email to [anything]@parse.[domain]
.
console.log('dkim: ', body.dkim)
console.log('to: ', body.to)
console.log('cc: ', body.cc)
console.log('from: ', body.from)
console.log('subject: ', body.subject)
console.log('sender_ip: ', body.sender_ip)
console.log('spam_report: ', body.spam_report)
console.log('envelope: ', body.envelope)
console.log('charsets: ', body.charsets)
console.log('SPF: ', body.SPF)
console.log('spam_score: ', body.spam_score)
These are the additional properties returned whether you have POST the raw, full MIME message
checked or not.
if (rawFullMimeMessageChecked) {
console.log('email: ', body.email)
} else {
console.log('headers: ', body.headers)
console.log('html: ', body.html)
console.log('text: ', body.text)
console.log('attachments: ', body.attachments)
console.log('attachment-info: ', body['attachment-info'])
console.log('content-ids: ', body['content-ids'])
}