How can I test sending email from my application without flooding my inbox?
Is there a way to tell IIS/ASP.NET how to deliver email to a local folder for inspection?
How can I test sending email from my application without flooding my inbox?
Is there a way to tell IIS/ASP.NET how to deliver email to a local folder for inspection?
Yes there is a way.
You can alter web.config like this so that when you send email it will instead be created as an .EML file in c:\LocalDir.
<configuration>
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\LocalDir"/>
</smtp>
</mailSettings>
</system.net>
</configuration>
You can also create an instance of the SmtpClient
class with these same settings, if you don't want to/can't change the web.config. In C# that looks something like this:
var smtpClient = new SmtpClient();
smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
var emailPickupDirectory = HostingEnvironment.MapPath("~/EmailPickup");
if (!Directory.Exists(emailPickupDirectory)) {
Directory.CreateDirectory(emailPickupDirectory)
}
smtpClient.PickupDirectoryLocation = emailPickupDirectory;
Configure rules in your email client to move the messages based on the subject/sender's email address?