如何MailMessage对象保存到磁盘为* .eml时或* .msg文件 [英] How to save MailMessage object to disk as *.eml or *.msg file
问题描述
我如何MailMessage对象保存到磁盘?该MailMessage对象不公开任何保存()方法。
我没有问题,如果它保存在任何格式,名为* .eml或*。味精。任何想法如何做到这一点?
为了简单起见,我就从一个的连接项:
您可以实际配置 SmtpClient发送邮件到文件 系统,而不是网络。您可以 做到这一点编程方式使用 下面code:
SmtpClient客户端=新SmtpClient(mysmtphost); client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory; client.PickupDirectoryLocation = @C:\ somedirectory; client.Send(消息);
您还可以设置这个在您的 像应用程序配置文件 这样的:
<结构>
< system.net>
< mailSettings>
< SMTP deliveryMethod =SpecifiedPickupDirectory>
< specifiedPickupDirectory pickupDirectoryLocation =C:\ somedirectory/>
< / SMTP>
< / mailSettings>
< /system.net>
< /结构>
发送电子邮件,你应在 看到电子邮件文件被添加到 你指定的目录。然后,您可以 有一个单独的进程发出的 电子邮件在批处理模式。
您应该能够使用空的构造,而不是列出的一个,因为它不会被反正发送。
How do I save MailMessage object to the disk? The MailMessage object does not expose any Save() methods.
I dont have a problem if it saves in any format, *.eml or *.msg. Any idea how to do this?
For simplicity, I'll just quote an explanation from a Connect item:
You can actually configure the SmtpClient to send emails to the file system instead of the network. You can do this programmatically using the following code:
SmtpClient client = new SmtpClient("mysmtphost"); client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory; client.PickupDirectoryLocation = @"C:\somedirectory"; client.Send(message);
You can also set this up in your application configuration file like this:
<configuration>
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="C:\somedirectory" />
</smtp>
</mailSettings>
</system.net>
</configuration>
After sending the email, you should see email files get added to the directory you specified. You can then have a separate process send out the email messages in batch mode.
You should be able to use the empty constructor instead of the one listed, as it won't be sending it anyway.
这篇关于如何MailMessage对象保存到磁盘为* .eml时或* .msg文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!