Wednesday, June 18, 2014

How to send an Email using Gmail SMTP server.

How to send an Email using Gmail SMTP server.

Hi, here is simple way to send an email using Gmail SMTP server. Create a form in visual studio with below fields in image.

Add a button to rename it “btnSend”

Now add the following code in btnsend_Click event.

private void btnSend_Click(object sender, EventArgs e)
                //Create object of System.Net.Mail.MailMessage
                MailMessage email = new MailMessage();

                SmtpClient SmtpServer = new SmtpClient("");

                //Sender Address
                email.From = new MailAddress(txtFrom.Text);

                //Receiver Address
                email.Subject = TxtSubject.Text;
                email.Body = txtMessage.Text;

                //Email Attachment
                if (linkLabel1.Text.Trim() != "")
                    System.Net.Mail.Attachment attachment;
                    attachment = new System.Net.Mail.Attachment(linkLabel1.Text);

                SmtpServer.Port = 587; //  Gmail SMTP Port
                //Sender User/Password.
                SmtpServer.Credentials = new System.Net.NetworkCredential(txtUser.Text.Trim(), txtPassword.Text.Trim());
                SmtpServer.EnableSsl = true;

                linkLabel1.Text = "";
                MessageBox.Show("send Successfully.");
            catch (Exception ex)

Test the application and enjoy!!!!

Search This Blog