How do I serialize a mail message?

后端 未结 3 525
野的像风
野的像风 2021-02-08 05:02

I get the following when tying to serialize a mial message using the los foratter.

Error: Sys.WebForms.PageRequestManagerServerErrorException: Error serializing value \'

3条回答
  •  迷失自我
    2021-02-08 05:13

    Sadly, the System.Net.Mail.MailMessage class is not marked as serializable. So, yes, you'll need to do it yourself. There's a technique described in the following blog post that can give you an idea of how you might proceed: How to Serialize a MailMessage ... basically, you will need to pull out each of the properties individually. Quote:

    To serialize the properties of a MailMessage object you can create a new class and create a property of MailMessage type for it that embeds your MailMessage in the class. In this new class you can implement IXmlSerializable interface to manually serialize its MailMessage. Here I create this class and call it SerializableMailMessage [...]

    [code implementation of WriteXml() and ReadXml() methods follow; see source link]

提交回复
热议问题