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

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

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

or using the configuration file:

<configuration>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="SpecifiedPickupDirectory">
        <specifiedPickupDirectory pickupDirectoryLocation="C:\somedirectory" />
      </smtp>
    </mailSettings>
  </system.net>
</configuration>
+12
source

You can configure SmtpClient to send emails to a configured directory, rather than send them. To do this, you need to install DeliveryMethodon SpecifiedPickupDirectoryand install PickupDirectoryLocation:

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

When sending letters using the standard, SmtpClientthey will now be saved in the specified directory instead of the actual sending.

+5

, SmtpClient, .

Write your own SMTP implementation (it’s very simple) that writes messages that are sent through it to disk, rather than sending them via email.

Then

// mailMessage is MailMessage
var client = new SmtpClient("address.of.your.smtp.implementation");
client.Send(mailMessage);

Your server will now intercept this send request and write it to disk.

0
source

All Articles