将Mandrill JSON webhook入站电子邮件附件映射到c#类



我可以处理来自Mandrill的JSON webhook入站电子邮件,但不能处理JSON消息的附件部分。

下面是我创建的c#类:

public class MandrillInbound
{
    public string @event { get; set; }
    public int ts { get; set; }
    public InboundMsg msg { get; set; }
}
public class InboundMsg
{
    public string raw_msg { get; set; }
    //public Headers headers { get; set; }
    public string text { get; set; }
    public bool text_flowed { get; set; }
    public string html { get; set; }
    public List<Attachment> attachments { get; set; }
    public string from_email { get; set; }
    public string from_name { get; set; }
    public List<List<string>> to { get; set; }
    public string subject { get; set; }
    //public Spf spf { get; set; }
    //public SpamReport spam_report { get; set; }
    //public Dkim dkim { get; set; }
    public string email { get; set; }
    public List<object> tags { get; set; }
    public object sender { get; set; }
    public object template { get; set; }
}
public class Attachment
{
    public string name { get; set; }
    public string type { get; set; }
    public string content { get; set; }
    public bool base64 { get; set; }
}

问题似乎是来自Mandrill的JSON格式的附件,如下所示:

"attachments":{
"Attachment1.txt":{"name":"Attachment1.txt","type":"text/plain","content":"Test attachment 1","base64":false},
"Attachment2.txt":{"name":"Attachment2.txt","type":"text/plain","content":"Test attachment 2","base64":false}
}

我已经联系了Mandrill,他们非常有帮助,但作为一个PHP机构,他们还没有能够提供一个解决方案。Mandrill入站邮件API的规范如下:https://mandrill.zendesk.com/hc/en-us/articles/205583207-What-is-the-format-of-inbound-email-webhooks-

人们认为映射到JSON附件的类结构应该是什么?我使用JSON。. Net解析JSON。

多谢蒂姆

您应该这样定义您的InboundMsg类:

public class InboundMsg
{
    // Other properties as before
    Dictionary<string, Attachment> attachments { get; set; }
}

Json。. NET可以将JSON对象反序列化为。NET泛型字典,使属性名成为字典键,使属性值成为字典值,这就是您在这里要做的。

相关内容

  • 没有找到相关文章

最新更新