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