如何将MailMessage对象保存为* .eml或* .msg文件 [英] How to save MailMessage object to disk as *.eml or *.msg file

查看:337
本文介绍了如何将MailMessage对象保存为* .eml或* .msg文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将MailMessage对象保存到磁盘? MailMessage对象不显示任何Save()方法。

How do I save MailMessage object to the disk? The MailMessage object does not expose any Save() methods.

如果以任何格式保存* .eml或* .msg,我没有问题。任何想法如何做到这一点?

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:


您实际上可以配置
SmtpClient将邮件发送到文件
系统而不是网络。您可以
以编程方式使用
以下代码:

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屋!

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