Skip to content

Instantly share code, notes, and snippets.

@wullemsb
Created May 18, 2013 08:14
A small wrapper class to send emails - Used as a sample as a hard to test implementation(we cannot replace the SmtpClient itself)
/// <summary>
/// Implementation of the mail sender service.
/// </summary>
public class MailSenderService
{
/// <summary>
/// Sends the mail using the specified options.
/// </summary>
/// <param name="mail">The mail.</param>
/// <param name="mailOptions">The mail options.</param>
public void SendMail(Mail mail, MailOptions mailOptions)
{
SmtpClient client = new SmtpClient();
if (mailOptions.SaveToFile)
{
client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
client.PickupDirectoryLocation = mailOptions.FilePath;
}
client.Send(mail.GetMailMessage());
Trace.TraceInformation("Send mail successfully with subject : '{0}' from '{1}'.".FormatWith(mail.Subject, mail.FromAddress.Address));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment