
- NODEJS SENDGRID EMAIL PARSER HOW TO
- NODEJS SENDGRID EMAIL PARSER CODE
- NODEJS SENDGRID EMAIL PARSER FREE
The SendGrid Inbound Parse is a great way of receiving emails and the processing them further on in a Azure Function is very practical. But with the help of two great opensource projects, for parsing the multipard/form-data and for parsing the email content I got this feature implemented in half the time. When I started thinking about this feature and how I will implement it I thought this will take much more time and effort. Log.LogInformation(JsonConvert.SerializeObject(data, Formatting.Indented)) īody = (JsonConvert.SerializeObject(data)) To = inboundMail.To.FirstOrDefault()?.Email,įrom = ExtractEmail(),īookingNumber = GetBookingNumberFromEmail(inboundMail.To.FirstOrDefault()?.Email), Var email = EmailParser.Parse(inboundMail.Text) The visible text will be the text that the user replied and not the whole text of the email with the original email. Use an email parser to get only the visible text. Var inboundMail = parser.ParseInboundEmailWebhook(req.Body) Use StrongGrid to parse the request body (handling multipart/form-data is not so simple) Inside of the application I handle messages that are being added to the queue and extract the information required. Then the final step for now is to create an anonymous object, pack all the data that is required into it and then create a new entry on the Azure Queue. This project is not very active so I might have to change it later on, but for now it does what it needs to. For this I am using the following NuGet package. In this application I only want the reply that the user sent, without the history. Then I use another library to parse the text of the email. This will return a strongly typed object with all the data that was sent from SendGrid. First I parse the request body with the mentioned library StrongGrid.
NODEJS SENDGRID EMAIL PARSER CODE
The whole code of the function looks like this. Inside of the Azure Function (That is setup the same way as in this blog post) I use the StrongGrid library that has a WebhookParser that parses the request body into a strongly typed object. This has proven to be very stable and a good pattern to use for these kind of cases. After the function has done its magic it creates an entry in an Azure Queue that then is handled by the ASP.NET Core Application. The main benefit is the availability and to encapsulate the logic. Instead of implementing this on a controller method inside my ASP.NET Core Application I use an Azure Function to handle this for me. If SendGrid receives an email on the configured domain it will create a POST request to a defined endpoint. I will be using the same approach that I have been using in this blog post. It is also required to add a MX record to the DNS of the domain that is setup with SendGrid.
NODEJS SENDGRID EMAIL PARSER HOW TO
How to setup SendGrid Inbound Parse can be found here. The Inbound Parse WebHook processes all incoming emails for a specific domain that is set in your DNS, parses the contents and the attachments and POSTs them as multipart/form-data to the defined URL.

SendGrid is not only great for sending emails, but they can also process incoming emails.

NODEJS SENDGRID EMAIL PARSER FREE
The Free Pricing Tier allows you to send 25'000 emails/month for free. Since I wanted to have everything manageable from inside the Azure Portal I went and created a new resource. Choose the one that better fits your application. The only difference is the pricing models. Prerequisitesįirst you need to create an account with SendGrid or create a SendGrid resource from your Azure Portal. To reduce the usage of outlook and having information in more than one place it would be great if the front desk can send emails to a guest through the application, the guest then answers to this email and instead of having to copy the information from an email client into the system, the system receives the email and adds it to the application as required. I also had this feature request for a hotel management application. These emails are then processed by the application and the content is added to the issue for example. Many applications like GitHub or Zendesk allow users to answer to system generated emails.

In this blog post I want to show how I integrated SendGrid's Inbound Parse into an ASP.NET Core Application to allow your application to receive emails from users.
