tags:

views:

1114

answers:

4

I am using SmtpClient to send an email with an attachment. However for a certain batch we need to somehow save the MailMessage instead of sending them. We are then thinking/hoping to manually upload the messages to the users drafts folder.

Is it possible to save these messages with the attachment intact (impossible, I would have thought). Or alternatively upload the messages to a folder in the users account?

If anyone has any experience of this, I'd much appreciate a bit of help or a pointer.

A: 

This is highly dependent on the e-mail client and its automation API. SMTP is a mail sending and transferring protocol. It has no faculty for saving or even retrieving e-mail.

Jekke
+2  A: 

There is a system.net setting in app.config file.

http://weblogs.asp.net/dfindley/archive/2006/04/23/Migrating-from-System.Web.Mail-to-System.Net.Mail.aspx

<system.net>

    <mailSettings>

      <smtp deliveryMethod="Network">

        <network host="mail.mydomain.com" port="25" />

      </smtp>

      <!-- Use this setting for development

      <smtp deliveryMethod="SpecifiedPickupDirectory">

        <specifiedPickupDirectory pickupDirectoryLocation="C:\Temp" />

      </smtp>
  -->

</mailSettings>

dotjoe
+5  A: 

In ASP .Net when testing we save our emails to a folder rather then send. Maybe you could change your settings like this for your batch?

    <system.net>
 <mailSettings>
  <smtp deliveryMethod="SpecifiedPickupDirectory">
   <specifiedPickupDirectory pickupDirectoryLocation="c:\Temp\mail\"/>
  </smtp>
 </mailSettings>
</system.net>
Leah
Thanks worked a treat. Also Avram (see below) posted a useful link which discusses changing the email message name from the auto generated GUID to your own value.
+1  A: 

This can help - Adding Save() functionality to Microsoft.Net.Mail.MailMessage

Avram
Thanks, it will be interesting to see whether I can add attachments here too.