Send Email

   In this post, we will see how to  send email using C#.net. and ASP.net

 

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("smtp.live.com");

client.Port = 25;

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

client.Credentials = nc;

client.Send(
"satalajmore@hotmail.com", "sat@gmail.com", "TEST_Subject", "Test Body");

 

 

 

}

}

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

     // it listens on port 587                     

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

    // gmail uses secure socket while communicating to the server

     s.UseDefaultCredentials = false;      

     s.Credentials = nc;                                                                               

     // assign networs credentials

     s.Send("myname@gmail.com", 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.

 

    


--Satalaj

Author

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 ASP.net 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.