Do you have a integration test for your send mail code?

Last updated by Tiago Araújo [SSW] almost 2 years ago.See history

This rule has been archived
Archived Reason: Sending emails in applications is usually handled through 3rd party providers nowadays e.g. SendGrid. As a result mail sending checks should be covered off by HealthChecks

The code below shows how you could use TestSmtpServer to test your send mail code:

DotNetOpenMailProvider provider = new DotNetOpenMailProvider();
NameValueCollection configValue = new NameValueCollection();
configValue["smtpServer"] = "";
configValue["port"] = "8081";
provider.Initialize("providerTest", configValue);
TestSmtpServer receivingServer = new TestSmtpServer();
 receivingServer.Start("", 8081);
 "Subject to nothing", 
 "Mr. Watson. Come here. I need you.");
// So Did It Work?
Assert.AreEqual(1, receivingServer.Inbox.Count);
ReceivedEmailMessage received = receivingServer.Inbox[0];
Assert.AreEqual("", received.ToAddress.Email);

Figure: This code could help you validate the send mail code

We open source. Powered by GitHub