I have some code in my asp.net which sends an email:
public void SendEmail(string message)
{
var body = message;
var email = new MailMessage(ConfigurationManager.AppSettings["SenderEmail"],
ConfigurationManager.AppSettings["RecipientEmail"],
"Email Test", body);
var client = new SmtpClient();
client.Host = Properties.Settings.Default.smtp;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.Send(email);
}
I'm wanting to know how to test this. Whether it is a unit test or integration test I really just don't care. I'm NOT wanting to mock this out. I'm actually wanting to write a test that an email is sent with the correct message.
Can anyone help me with this?
Just create a folder called "maildrop" on your c:/ drive and use the following in your Web.config file:
<mailSettings>
<smtp deliveryMethod='SpecifiedPickupDirectory'>
<specifiedPickupDirectory pickupDirectoryLocation="c:\maildrop" />
</smtp>
</mailSettings>
More information:
http://weblogs.asp.net/gunnarpeipman/archive/2010/05/27/asp-net-using-pickup-directory-for-outgoing-e-mails.aspx
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