22

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?

1
  • Don't close questions like this. Help the guy out instead.
    – GEOCHET
    Oct 7, 2008 at 11:39

2 Answers 2

44

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;
1

Configure rules in your email client to move the messages based on the subject/sender's email address?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.