Lonely Planeteer
Lonely Planeteer

Reputation: 389

I am unable to parse message-header sent by MailGun to Json

[
["Received", "by luna.mailgun.net with SMTP mgrt 8734663311733; Fri, 03 May 2013 18:26:27 +0000"], 
["Content-Type", ["multipart/alternative", {"boundary": "eb663d73ae0a4d6c9153cc0aec8b7520"}]], 
["Mime-Version", "1.0"], ["Subject", "Test bounces webhook"], 
["From", "Bob <[email protected]>"], 
["To", "Alice <[email protected]>"], 
["Message-Id", "<[email protected]>"], 
["List-Unsubscribe", "<mailto:u+na6tmy3ege4tgnldmyytqojqmfsdembyme3tmy3cha4wcndbgaydqyrgoi6wszdpovrhi5dinfzw63tfmv4gs43uomstimdhnvqws3bomnxw2jtuhusteqjgmq6tm@rs19930.mailgun.org>"], 
["X-Mailgun-Sid", "WyIwNzI5MCIsICJhbGljZUBleGFtcGxlLmNvbSIsICI2Il0="], 
["X-Mailgun-Variables", "{\"my_var_1\": \"Mailgun Variable #1\", \"my-var-2\": \"awesome\"}"], 
["Date", "Fri, 03 May 2013 18:26:27 +0000"], ["Sender", "[email protected]"]
]

I am getting this as a message-header from mailgun. I need to parse this header into json. I have tried JObject.Parse(message_headers) and JArray.Parse(message_headers). But it does not work.

When I remove ["X-Mailgun-Variables", "{\"my_var_1\": \"Mailgun Variable #1\", \"my-var-2\": \"awesome\"}"] this it seems to work.

Please let me know what I am doing wrong.

Upvotes: 1

Views: 438

Answers (1)

Andrew Kendall
Andrew Kendall

Reputation: 31

The problem is that Mailgun headers are not JSON objects. I ran into this same problem and the way I solved it was to parse out the values I needed and manually convert them to a JSON object.

Upvotes: 1

Related Questions