How to send email in C# from The code is not workinfg

//Error - System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required

using System;
using System.Configuration;
using System.Data;
using System.Web.Mail;
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;

public partial class Default2 : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
    protected void btnSend_Click(object sender, EventArgs e)
        int port = 587;
        System.Net.Mail.MailMessage objMail = new System.Net.Mail.MailMessage();
        System.Net.Mail.SmtpClient objSmtp = new System.Net.Mail.SmtpClient("",port);

            objMail.From = new System.Net.Mail.MailAddress("");
            //This code of line is used for specifying the subject line.
            objMail.Subject = txtSubject.Text;
            objMail.IsBodyHtml = true;
            objMail.Body = txtContent.Value;

            objSmtp.UseDefaultCredentials = false;
            objSmtp.Credentials = new System.Net.NetworkCredential("", "******");
            objSmtp.EnableSsl = true;

            Response.Write("<script>alert('Email sent');</script>");
        catch (Exception ess)

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


If you've tried sending multiple times, google might have placed a temp block, which puts a "word verification" (captcha). Sign in via web interface, check your credentials and fill in captcha. Has that helped?
According to, the port for SSL is 465, try that instead.
AshokSr. Software EngineerCommented:
using System.Net.Mail;

protected void btnSend_Click(object sender, EventArgs e)
  MailMessage mail = new MailMessage();
  mail.From = new MailAddress("");
  mail.Subject = "Email using Gmail";

  string Body = "Hi, this mail is to test sending mail"+
                "using Gmail in ASP.NET";
  mail.Body = Body;

  mail.IsBodyHtml = true;
  SmtpClient smtp = new SmtpClient();
  smtp.Host = ""; //Or Your SMTP Server Address
  smtp.Port = 587;
  smtp.Credentials = new System.Net.NetworkCredential
//Or your Smtp Email ID and Password
  smtp.EnableSsl = true;

If this does not help, see


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
searchsanjaysharmaAuthor Commented:
Thanks excellent
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.