How to parse data from request posted by Mailgun? C#

946 Views Asked by At

I am trying to get data from the posted request by Mailgun for bounced emails and put it in an error log. However, I can't find a way to do this.

The request from mailgun looks like this:

--127.0.0.1.1001.72643.1217418299.480.49
Content-Disposition: form-data; name="domain"

beta.mysite.mailgun.org
--127.0.0.1.1001.72643.1217418299.480.49
Content-Disposition: form-data; name="code"

605
--127.0.0.1.1001.72643.1217418299.480.49
Content-Disposition: form-data; name="description"

Not delivering to previously bounced address
--127.0.0.1.1001.72643.1217418299.480.49
Content-Disposition: form-data; name="my_var_1"

Mailgun Variable #1
--127.0.0.1.1001.72643.1217418299.480.49
Content-Disposition: form-data; name="reason"

hardfail
--127.0.0.1.1001.72643.1217418299.480.49
Content-Disposition: form-data; name="my-var-2"

awesome

and I want my Errorlogfile.txt to have something like this:

domain: beta.mysite.mailgun.org
code: 605
description: Not delivering to previously bounced address
my_var_1: Mailgun Variable #1
reason: hardfail
my-var-2: awesome

I don't know if my question is clear so please ask me for clarifications if there's any. Tnx!

1

There are 1 best solutions below

2
On

If the message pattern repeats with the same order for each message groups, then it may be easy to create a parser that processes the messages and generates the text you want in the format you want. Let me know if you are creating an app in C# for this. If so, I can write you some code to accomplish your task.