如何序列化邮件? [英] How do I serialize a mail message?

查看:117
本文介绍了如何序列化邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试使用los foratter序列化mial消息时,我得到以下信息。

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

错误:Sys.WebForms.PageRequestManagerServerErrorException:序列化值'System.Net时出错。类型为 System.Net.Mail.MailMessage的Mail.MailMessage。

Error: Sys.WebForms.PageRequestManagerServerErrorException: Error serializing value 'System.Net.Mail.MailMessage' of type 'System.Net.Mail.MailMessage.'

是否有一种简便的方法来序列化此对象,或者我必须对每个对象进行序列化?

Is there an EASY way to serialize this object or am I going have to searialize each o fhte properties individually?

推荐答案

遗憾的是,System.Net.Mail.MailMessage类未标记为可序列化。因此,是的,您需要自己做。以下博客文章中介绍了一种技术,可以使您了解如何进行:如何序列化MailMessage ...基本上,您将需要分别提取每个属性。 Quote:

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:


要序列化MailMessage对象的属性,您可以创建
新类并为以下对象创建MailMessage类型的属性它将
您的MailMessage嵌入类中。在这个新类中,您可以实现
IXmlSerializable接口来手动序列化其MailMessage。在这里
我创建了这个类,并将其称为SerializableMailMessage [...]

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 [...]

[WriteXml()和ReadXml()方法的代码实现;参见源链接]

这篇关于如何序列化邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆