Send Email using Gmail from C# using MailMessage class

You can send email from C# using MailMessage class. In this example i have explained how to send email using Gmail SMTP server.

You can also check " Send Email with Attachments" and " Send Email by requesting delivery/read receipt from C#"

Please find below C# source code, that shows how to send an email from a Gmail address using SMTP server. The Gmail SMTP server name is and the port using send mail is 587 and also using NetworkCredential for password based authentication.
I have created sample windows application and added button = btnSendEmailUsingGmail, in this button click event the below code added.

using System;
using System.Net.Mail;
using System.Windows.Forms;

namespace SampleWindowsApp
    /// <summary>
    /// Send Email Form 
    /// </summary>
    /// <seealso cref="System.Windows.Forms.Form" />
    public partial class SendEmailForm : Form
        /// <summary>
        /// Initializes a new instance of the <see cref="SendEmailForm"/> class.
        /// </summary>
        public SendEmailForm()

        /// <summary>
        /// Handles the Click event of the btnSendEmailUsingGmail control.
        /// Author = Himasagar Kutikuppala
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void btnSendEmailUsingGmail_Click(object sender, EventArgs e)
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("");

                //Change below gmail address & To email address
                mail.From = new MailAddress("");
                mail.Subject = "Test Mail From Gmail";
                mail.Body = "This is for testing SMTP mail from GMAIL";

                SmtpServer.Port = 587;
                //Change your gmail user id & password
                SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
                SmtpServer.EnableSsl = true;

                MessageBox.Show("The email has been sent successfully.");
            catch (Exception ex)

What is GST

GST (Goods and Service Tax) is a comprehensive tax on the supply of goods and services at each stage of any transaction. Read More

Income Tax Information

An income tax is a tax imposed by government on income earned by you. Income tax is a key source of funds that the government uses to fund its activities and serve the public. Read More

General Insurance Companies in India

General insurance is insurance for valuables other than our life and health. General insurance covers the insurer against damage, loss and theft of your valuables. Read More

Types of Bank Loans In India

Loan means lending money from one individual or entity to another. A loan has three components – principal or the borrowed amount, rate of interest and tenure or duration for which the loan is availed. Read More

List of Banks in India

The Reserve Bank of India is the central Bank that is fully owned by the Government of India. It is governed by a central board (headed by a Governor) appointed by the Central Government. Read More

List of Educational Institutions in India

The following list of comprehensive websites on higher education in India. These websites will provide detailed information on education system in India. Read More