Want a free Ebook & latest Update Subscribe Now
  [email protected]      beta
Donate

How to send email with google gmail account in asp.net?

 
Here in this article we demonstrate how to send an email with using your Google, gmail account in Asp.net c#. Sending Email is a common task of a web application for many purposes like- Error logging, Reporting, Newsletters as well as for many other reasons.Gmail is a good solution for this purpose. Gmail provides SMTP and POP access which can be utilized for sending and receiving E-mails.

Code to send email in asp.net c# with your gmail google account:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Net.Mail;
 
 
// system.net.mail namespace is used for emailing.
  protected void btnsubmit_Click(object sender, ImageClickEventArgs e)
 {  
     //Code for send Email
        MailMessage sendMailforSA = new MailMessage();
        SmtpClient smtpforSA = new SmtpClient();
        string subjectforSA = null;
        subjectforSA = "Thanks for apply";
        System.Net.NetworkCredential credforSA = new System.Net.NetworkCredential("Superman@gmail.com", "password");
        sendMailforSA.To.Add(txtemailid.Value);
        MailAddress cc = new MailAddress("info@superman.com");
        sendMailforSA.CC.Add(cc);

        // sendMailforSA.CC("abcxxx@gmail.com");
        sendMailforSA.From = new MailAddress("Rajnikant@gmail.com");
        sendMailforSA.Subject = subjectforSA.ToString();
        sendMailforSA.Body =" Thank you.... your message you can use html tag for style effect";
        sendMailforSA.IsBodyHtml = true;
        smtpforSA.Host = "smtp.gmail.com";
        smtpforSA.Port = 25;
        smtpforSA.EnableSsl = false;
        smtpforSA.UseDefaultCredentials = false;
        smtpforSA.Credentials = credforSA;
        smtpforSA.Send(sendMailforSA);
}

Share:    
Satinder Singh

Hi all, am Founder and Author of Codepedia.info, also atypical polyglot programmer from Bombay, India. I have a passion to create, solve, and deploy software applications.
       ForEach ( minute in MyLife ) { myExperience++ ; }


3 comments on “How to send email with google gmail account in asp.net?”

  1. Lelala

    Nice idea, but the problem is:
    Your website stops loading due the handshake with the foreign SMTP server is done, meaning the site will hang for one or two seconds.
    Better you start a simple background thread for actually sending the mail, so the user will have no delay.

  2. Mass Emails

    Hello,

    Nice post. I like the way you start and then conclude your thoughts. Send Email offers an easy to use, free email encryption service with a simplified registration process. Thanks for this information.I really appreciate your work, keep it up…


Post Comment


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