send email using gmail in asp.net(smtp)

namespace

using System.Net.Mail;

protected void Button1_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new   System.Net.NetworkCredential("youremailaddress@gmail.com", "yourpassword");
smtp.EnableSsl = true;
mail.To.Add("test@gmail.com");
mail.From = new MailAddress("test@gmail.com");
mail.Subject = "test";
mail.Body = "object reference not found.";
mail.IsBodyHtml = true;
smtp.Send(mail);
mail.Dispose();
}

if you are getting problems in Port no….

then replace above code with this.

protected void Button1_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new   System.Net.NetworkCredential("youremailaddress@gmail.com", "yourpassword");

<strong>smtp.UseDefaultCredentials = False;</strong>

<strong>smtp.Port = 587;</strong>
smtp.EnableSsl = true;
mail.To.Add("test@gmail.com");
mail.From = new MailAddress("test@gmail.com");
mail.Subject = "test";
mail.Body = "object reference not found.";
mail.IsBodyHtml = true;
smtp.Send(mail);
mail.Dispose();
}



Advertisements
This entry was posted in Asp.Net. Bookmark the permalink.

One Response to send email using gmail in asp.net(smtp)

  1. TomTorson says:

    Nice blog if you ask me. Thanks for enlightning this data.

    Tom Torson
    cell phone signal jammers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s