Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write email on disk instead of sending to real address in asp.net?

Tags:

c#

email

asp.net

How to write email (.eml file) on disk instead of sending to real address in asp.net? Thanks in advance.

like image 227
apros Avatar asked Jan 16 '11 16:01

apros


2 Answers

using (var client = new SmtpClient("somehost"))
{
    client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
    client.PickupDirectoryLocation = @"C:\somedirectory";
    client.Send(message);
}

or using the config file:

<configuration>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="SpecifiedPickupDirectory">
        <specifiedPickupDirectory pickupDirectoryLocation="C:\somedirectory" />
      </smtp>
    </mailSettings>
  </system.net>
</configuration>
like image 192
Darin Dimitrov Avatar answered Nov 04 '22 05:11

Darin Dimitrov


You can configure the SmtpClient to put emails into a configured directory instead of sending them. To do this, you need to set the DeliveryMethod to SpecifiedPickupDirectory and set the PickupDirectoryLocation:

<system.net>
    <mailSettings>
        <smtp deliveryMethod="SpecifiedPickupDirectory">
            <specifiedPickupDirectory pickupDirectoryLocation="C:\emails" />
        </smtp>
    </mailSettings>
</system.net>

When you send emails using the standard SmtpClient, they will now get saved to the specified directory instead of actually being sent.

like image 5
adrianbanks Avatar answered Nov 04 '22 07:11

adrianbanks