Just another plug for a very helpful tool that I’ve been using for testing SMTP code locally. Smtp4dev simulates an SMTP server on your local machine, allowing you to send email via a local SMTP connection in your code when you do not have a SMTP server setup. You can even inspect the messages to ensure that they are exactly as intended, with the subject, body, etc. Very simple, but useful tool that I find myself using quite often. http://smtp4dev.codeplex.com/ (see below for a basic example of sending a message via smtp locally)
public static void SendEmail(string aFrom, string aTo, string aSubject, string aBody) { //create the mail message MailMessage mail = new MailMessage(); //set the addresses mail.From = new MailAddress(aFrom); mail.To.Add(aTo); //set the content mail.Subject = aSubject; mail.Body = aBody; //send the message SmtpClient smtp = new SmtpClient("localhost"); smtp.UseDefaultCredentials = true; smtp.Send(mail); }
Leave A Comment