save System.Net.mail.MailMessage as .msg file

﹥>﹥吖頭↗ 提交于 2019-12-03 02:36:09
Arsen Mkrtchyan

Here Ryan suggests an easy and great way to do it whithout any effort.

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>
Martin Vobr

If you are referring to Outlook MSG file format check the MSG format specification published by Microsoft. Following answer to similar question might also help.

If you are referring to the Outlook .msg file, this cannot be done natively in .NET.

The Outlook .msg file is a compound document, so, you would need to save it in that format, and be sure to put all of the appropriate properties in their exact locations.

You need to either write your own, use a 3rd party, or possible Outlook interop.

Sorry,

Dave

Check this short example that uses Outlook Interop library Creating an Outlook Message File with C# . It's not exactly what have you been asking for but there is a way to copy values from one to another - manually.

Microsoft Support KB article: INFO: Save Message to MSG Compound File

The error message given by Outlook is because of the .msg extension. I am using the same method to save MailMessage objects to disk and have found that the file will only open in outlook with an extension of .eml.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!