How to save MailMessage object to disk as *.eml or *.msg file

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.

Leave a Comment