Send Email

   In this post, we will see how to  send email using and


using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Net.Mail;

using System.Net;

public partial class SendEmail : System.Web.UI.Page


protected void Page_Load(object sender, EventArgs e)


SmtpClient client = new SmtpClient("");

client.Port = 25;

client.EnableSsl =
true;NetworkCredential nc = new NetworkCredential("", "Passw@rd");

client.Credentials = nc;

"", "", "TEST_Subject", "Test Body");






  System.Net.Mail.SmtpClient s = new System.Net.Mail.SmtpClient("", 587);             

     // it listens on port 587                     

     System.Net.NetworkCredential nc = new System.Net.NetworkCredential(, "mygmailPass");
     s.EnableSsl = true;                         

    // gmail uses secure socket while communicating to the server

     s.UseDefaultCredentials = false;      

     s.Credentials = nc;                                                                               

     // assign networs credentials

     s.Send("", email, "subject", "email body" );                // send email

For demo purpose I selected my gmail and Hotmail account. If you are tryuing this code then makesue that you have configured your gmail settings to send email using third party softwares like outlook.





My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.

I'm Satalaj.