Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SendGrid parse inbound headers

I am using SendGrid to parse incoming messages using ASP.NET and C#.

NameValueCollection nvc = Request.Form;
System.Diagnostics.Trace.TraceError("Headers: " + nvc["headers"].ToString());

What is the best way to convert RAW headers into a collection?

I don't see any examples in the docs. https://sendgrid.com/docs/API_Reference/Webhooks/parse.html

like image 526
Mercer Avatar asked Feb 27 '26 18:02

Mercer


1 Answers

I ran into the same issue and couldn't find anything either, needed to extract the Message-ID from the headers String.

I ended up using Regex to extract the portion I needed. I used this pattern:

Message-ID: (<\\w*@(\\w*\\d*\\.*)*>)

It essentially extracts the data after Message-ID: of any string of the form: "Message-ID: " where the extracted text would be

<[email protected]>

The same principle can be applied to extract most data from the headers string. You can then turn that into any sort of collection.

Good resource if you're new to the subject: https://regexone.com/

http://www.rubular.com is a great place to test out your regular expressions in the browser

like image 186
Faizan Ali Avatar answered Mar 01 '26 11:03

Faizan Ali