How to write email (.eml file) on disk instead of sending to real address in asp.net? Thanks in advance.
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With