Learning While Aging

Sending email with Visual Studio 2008 in Windows 7 by using Free SMTP Server

You may already know that Microsoft dropped SMTP in client OS since Windows Vista, so apparently Windows 7 will not have SMTP either. If you need a SMTP on your local machine to test and debug your mail function as I do, you can install a free third-party SMTP server called Free SMTP Server. The installation is very straight forward and you don’t need to do any customization. In your application, just use “localhost” as the SMTP host and you are done. Here is an example of using Free SMTP Sever to send a test email in Visual Studio 2008 web application.

The SMTP settings can be stored in web.config:

<system.net>
  <mailSettings>
    <smtp deliveryMethod="Network">
      <network host="localhost"/>
    </smtp>
  </mailSettings>
</system.net>

A sample email snippet:

Dim mm As New MailMessage()
mm.To.Add("jeffrey@techproszone.net")
mm.Subject = "Test email from www.TechProsZone.net"
mm.Body = "This is a test email from http://www.TechProsZone.net"
mm.IsBodyHtml = True
Dim smtp As New SmtpClient()
smtp.Send(mm)

When the above code snippet is executing, you will see an active connection in Free SMTP Server shown as follows:

FreeSMTPServer

Note: you will need to keep Free SMTP Server running in order to use it to send email in your web application.