How to send email in ASP.NET with SMTP authentication

ASP.NET has a built-in class - System.Net.Mail - to send email. 

C# Code Sample

<%@ Import Namespace="System.Net" %>
 <%@ Import Namespace="System.Net.Mail" %>
<script language="C#" runat="server"> 
   protected void Page_Load(object sender, EventArgs e) 
            MailMessage mail = new MailMessage(); 
            mail.From = new MailAddress ( "" ); 
            mail.Subject = "This is a test message" ; 
            mail.Body = "If you can see this mail, your SMTP service is working" ; 
            mail.To.Add( "" ); 
            SmtpClient smtp = new SmtpClient( "[Mail Server name]" ); 
            NetworkCredential credential = new NetworkCredential ("" , "password"); 
            smtp.Credentials = credential; 
            Response.Write( "Message was sent to " + mail.To + " at " + DateTime .Now); 
If you want to send encrypted email, the SmtpClient class only supports SMTP over TLS which is available over port 25 or 587.
If you run into problems when using this code, please post in the DiscountASP.NET or Everleap community forum. Technical support is unable to assist with specific coding issues.