Skip to content

KoditkarVedant/sendgrid-inbound

Repository files navigation

Overview

SendGrid has an Email Inbound Parse Webhook which posts data from a specified incoming email address to a URL of your choice. This library allows you to quickly and easily deployable solution that help you easily get up and running processing (parse and complete some action) your inbound parse webhooks.

This is docker-based solution which can be deployed on cloud services like Heroku out of the box.

Table of Content

Prerequisite

Clone the repository

git clone https://github.com/KoditkarVedant/sendgrid-inbound.git

Move into the clonned repository

cd sendgrid-inbound

Restore the Packages

dotnet restore

Deploy locally

Setup your MX records. Depending on your domain name host, you may need to wait up to 48 hours for the settings to propagate.

Run the Inbound Parse listener in your terminal:

git clone https://github.com/KoditkarVedant/sendgrid-inbound.git

cd sendgrid-inbound

dotnet restore

dotnet run --project .\Src\Inbound\Inbound.csproj

Above will start server listening on a random port like below

In another terminal, use ngrok to allow external access to your machine:

ngrok http PORT_NUMBER

Update your SendGrid Incoming Parse settings: Settings Page | Docs

  • For the HOSTNAME field, use the domain that you changed the MX records (e.g. inbound.yourdomain.com)
  • For the URL field, use the URL generated by ngrok + /inbound, e.g http://XXXXXXX.ngrok.io/inbound

Next, send an email to [anything]@inbound.yourdomain.com, then look at the terminal where you started the Inbound Parse listener.

Deploy to Heroku

Create Heruko account if not already present

Install the Heroku CLI

Download and install the Heroku CLI.

If you haven't already, log in to your Heroku account and follow the prompts to create a new SSH public key.

$ heroku login

Now you can sign into Container Registry.

$ heroku container:login

Create app in heroku

$ heroku apps:create UNIQUE_APP_NAME

Push your Docker-based app Build the Dockerfile in the current directory and push the Docker image.

$ heroku container:push web --app UNIQUE_APP_NAME

Deploy the changes Release the newly pushed images to deploy your app.

$ heroku container:release web --app UNIQUE_APP_NAME

Testing the Source Code

You can get all the test cases inside the Tests folder.

Contribution

If you would like to contribute to this project, please see our contributing guide. Thanks!