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

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

问题描述

如何将 MailMessage 对象保存到磁盘?MailMessage 对象不公开任何 Save() 方法.

如果它以任何格式保存,*.eml 或 *.msg,我都没有问题.知道如何做到这一点吗?

解决方案

为简单起见,我将引用 连接项目:

<块引用>

你实际上可以配置SmtpClient 发送邮件到文件系统而不是网络.你可以使用编程方式执行此操作以下代码:

SmtpClient client = new SmtpClient("mysmtphost");client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;client.PickupDirectoryLocation = @"C:somedirectory";客户端发送(消息);

您也可以在您的应用程序配置文件,如这个:

 <配置><system.net><邮件设置><smtp deliveryMethod="SpecifiedPickupDirectory"><specifiedPickupDirectorypickupDirectoryLocation="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屋!

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