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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With