send email using gmail credentials in

we often require email sending functionality in our web application.
If we don’t have smtp server for sending mails then we can send mails by using gmail smtp server.

Here I will explain how to send email using gmail credentials in

protected void btnSubmit_Click(object sender, EventArgs e)
    MailMessage Msg = new MailMessage();
    Msg.From = new MailAddress("fromemailaddress");
    Msg.Subject = "Define your subject line";
    Msg.Body = "Content of body";

    SmtpClient smtp = new SmtpClient();
    smtp.Host = "";
    smtp.Port = 587;
    smtp.Credentials=new System.Net.NetworkCredential("gmailID","gmailpassword");
    smtp.EnableSsl = true;
  catch (Exception ex)
    //catch exception here

Note:You need to add System.Net.Mail namespace on your page.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>