SendGrid Inbound Parse with NodeJS

Rishav Kumar

9/16/20234 min read

In this blog post, we'll explore how to configure SendGrid's Inbound Parse Webhook with Node.js and Express.js, and validate its functionality using LocalTunnel. This setup empowers our application to effortlessly handle incoming emails.

Pre-requisite : A domain owned by you.

Setting up SendGrid

  • Head over to SendGrid and create a free account.

  • After creating your account, navigate to Settings > Sender Authentication, and click the "Authenticate Your Domain" button to verify your domain.

a website page with a list of the best email marketing services
a website page with a list of the best email marketing services
  • Follow the provided steps to complete domain authentication. Once successfully authenticated, you can view your authenticated domains listed here.

Now that all the necessary components are in order, let's delve into the code to detect and display received emails.

Creating a Project

  • Open a terminal at the folder where you want to create the project, then execute these commands:

  • Open index.js that you just created and write this code:

  • In the code above, we have created a POST API with the endpoint 'api/parse' to receive emails and display some of the details in console. here is a list of all the details in console

Setting up LocalTunnel

  • To install, open a terminal and execute npm install -g localtunnel OR yarn global add localtunnel. Alternatively you can also use HomeBrew in MacOS to install it by executing brew install localtunnel.

  • Once installed, to start the global server execute lt --port 3000.

Setting up Inbound Parse

  • Add the following details :

  • Subdomain (OPTIONAL) and select the domain from the dropdown (only verified domains will be shown).

  • Add the destination URL = {_localtunnel_url_}/api/parse (because that's the route name of the API we just created above)

  • Click "Check Incoming emails for spam"

  • Click on "Add" Button

  • Adding email records in domain registrar :

  • Type = MX (Email service providers authenticate domains using MX records)

  • Name = dev (If you are using a subdomain for inbound parse add that here, in my case it is 'dev', if you are not using a subdomain then the name will be '@' ) (P.S. The domain name is automatically added at the end of the subdomain by most of the service providers, in case it is not, the name will be {_subdomain_}.{_domain_name_} )

  • Mail Server or Address = mx.sendgrid.net. (P.S. Don't miss the dot at the end)

  • Priority = 10 (in case the option to add priority is not given, then the address will become 10 mx.sendgrid.net. )

  • TTL = Use the default value

  • Click on Add record or Submit Button

Putting Everything to Test

Now that we have set up inbound parse in SendGrid and have our server running on LocalTunnel, it's time to test it out. Here is a sample email I am sending to an email with the domain dev.whoisrishav.com

And there you have it, after a few seconds of sending the email, the email details are printed in our console

Thank you for taking the time to read this blog! We appreciate your interest and hope you found it valuable.

I also welcome any questions or discussions you may have, so feel free to reach out to me anytime via email or the form in the footer of this blog. Your feedback and engagement mean a lot to me!

To stay updated with our latest content, please consider subscribing so that you'll be notified whenever new blogs are published.

  • Log into your SendGrid account and head to Settings > Inbound Parse > Add Host URL

Connect With Me

Connect with me for a productive discussion, valuable consultation, or exciting collaboration. I am eager to engage with you and explore new ideas, strategies, and opportunities. Reach out to me today and let's embark on a journey of shared success.