简体   繁体   中英

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

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM