Saving Emails to Disk in C#
Sending emails in C# is a simple task. All you need is a MailMessage object with your email and a SmtpClient to send it:
|
The configuration for the SmtpClient is inside the web.config or app.config can look like this example from Sanjay kumar:
|
Whenever your code is executed, your email will be sent using the specified mail server. While this is great for production, it’s a different story for testing your code. Do you really want to send all those emails?
A Different Delivery Method
The great benefit of using a configuration based approach with the mail configuration settings is that you can change the configuration in the app.config and don’t need to modify your code. If you switch the configuration from above with this one, then the SmtpClient will store the emails instead of sending them:
Attention: make sure that the pickup directory exists. Otherwise you will get an exception.