I'm a student trying to work with mandrill and to be quite honest, I haven't a clue what I'm at.
I'm able to send emails no problem using mandrill in .net
What I want to do now is use webhooks to catch bounce emails at the moment and maybe more once I have accomplished that.
Here is the code I have so far (from the internet)
public ActionResult HandleMandrillWebhook(FormCollection fc)
{
string json = fc["mandrill_events"];
var events = JsonConvert.DeserializeObject<IEnumerable<Mandrill.MailEvent>>(json);
foreach (var mailEvent in events)
{
var message = mailEvent.Msg;
// ... Do stuff with email message here...
}
// MUST do this or Mandrill will not accept your webhook!
return new HttpStatusCodeResult((int)HttpStatusCode.OK);
and then I have this
public class MailEvent
{
[JsonProperty(PropertyName = "ts")]
public string TimeStamp { get; set; }
[JsonProperty(PropertyName = "event")]
public string Event { get; set; }
[JsonProperty(PropertyName = "msg")]
public Message Msg { get; set; }
}
public class Message
{
[JsonProperty(PropertyName = "raw_msg")]
public string RawMessage { get; set; }
[JsonProperty(PropertyName = "headers")]
public Header Header { get; set; }
[JsonProperty(PropertyName = "text")]
public string Text { get; set; }
[JsonProperty(PropertyName = "html")]
public string Html { get; set; }
[JsonProperty(PropertyName = "from_email")]
public string FromEmail { get; set; }
[JsonProperty(PropertyName = "from_name")]
public string FromName { get; set; }
// Not sure why Mandrill sends an array of arrays here...
[JsonProperty(PropertyName = "to")]
public string[][] To { get; set; }
[JsonProperty(PropertyName = "email")]
public string Email { get; set; }
[JsonProperty(PropertyName = "subject")]
public string Subject { get; set; }
[JsonProperty(PropertyName = "tags")]
public string[] Tags { get; set; }
[JsonProperty(PropertyName = "sender")]
public string Sender { get; set; }
[JsonProperty(PropertyName = "dkim")]
public DKIM DKIM { get; set; }
[JsonProperty(PropertyName = "spf")]
public SPF SPF { get; set; }
[JsonProperty(PropertyName = "spam_report")]
public SpamReport SpamReport { get; set; }
}
[JsonDictionary()]
public class Header : Dictionary<string, object>
{
// Need to find a nicer way of doing this... Dictionary<string, object> is kinda dumb
}
public class SpamReport
{
[JsonProperty(PropertyName = "score")]
public decimal Score { get; set; }
[JsonProperty(PropertyName = "matched_rules")]
public SpamRule[] MatchedRules { get; set; }
}
public class SpamRule
{
[JsonProperty(PropertyName = "name")]
public string Name { get; set; }
[JsonProperty(PropertyName = "score")]
public decimal Score { get; set; }
[JsonProperty(PropertyName = "description")]
public string Description { get; set; }
}
public class DKIM
{
[JsonProperty(PropertyName = "signed")]
public bool Signed { get; set; }
[JsonProperty(PropertyName = "valid")]
public bool Valid { get; set; }
}
public class SPF
{
[JsonProperty(PropertyName = "result")]
public string Result { get; set; }
[JsonProperty(PropertyName = "detail")]
public string Detail { get; set; }
}
Could somebody please show me how to process the mandrill webhook response then.
Its in json.
I have never done anything like this before. Am I missing much code?
Is json passed in as a file or raw code?
Thanks guys.
I really appreciate it.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…