Hello all,
I want to send a mail after my user fill a form but i keep getting the following error "The smtp server requires a secure connection or the client was not authenticated 5.5.1. Authentication required". bellow is my code :
- int cnt;
- try
- {
- mEmail = Session["mEmail"].ToString();
- // string password = "abraham@2013";
- MailMessage Msg = new MailMessage();
- Msg.From = new MailAddress(mEmail.Trim());
- Msg.To.Add("[email protected]"); // create a frame for HR department
- Msg.Bcc.Add("[email protected]"); //blind copy me
- StreamReader reader = new StreamReader(Server.MapPath("~/SendMail.html"));
- string readFile = reader.ReadToEnd();
- string StrContent = "";
- StrContent = readFile;
- //Here replace the name with [MyName]
- StrContent = StrContent.Replace("[MyName]", lblname.Text);
- string mSubject = "APPLICATION FOR ANNUAL LEAVE";
- StrContent = StrContent.Replace("[subject]", mSubject);
- StrContent = StrContent.Replace("[date1]", txtFromDate.Text.Trim());
- StrContent = StrContent.Replace("[date2]", txtToDate.Text.Trim());
- StrContent = StrContent.Replace("[ddays]",txtNODays.Text.Trim())+" days";
- Msg.Subject = mSubject + " FROM " + lblname.Text;
- Msg.Body = StrContent.ToString();
- Msg.IsBodyHtml = true;
- SmtpClient smtp = new SmtpClient();
- smtp.Host = "smtp.gmail.com"; //"mail.dnextageweb.com"; //
- smtp.Port = 587;
- smtp.EnableSsl = true;
- smtp.Timeout = 40000;
- smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
- smtp.UseDefaultCredentials = false;
- smtp.Credentials = new NetworkCredential("[email protected]", "Delladv!973@");
- smtp.Send(Msg);
- webMessage.Show("Mail sent successful.....");
- return cnt = 1;
- }
- catch (Exception ex)
- {
- webMessage.Show("Error : " + ex.Message.ToString());
- return cnt = -1;
- }
please i have tried all i know, i need your help, how to get smtp.gmail.com to work.
Thank you all


Nilesh ShahRank #42 · 34.2K reputationPosted Jan 24, 2017, 5:55 AM EST
If that is OK, and still you face issues, then there is possibility that Google security settings are blocking your code.
When you try to login from some App or code, google setting comes into picture.
Log in to your google account
Go to https://myaccount.google.com/security
And scroll down to "Connected apps & sites"
Hope this helps!
Amit GuptaRank #190 · 12.8K reputationPosted Jan 24, 2017, 5:22 AM EST
Francis SusaimichaelRank #466 · 5.4K reputationPosted Jan 24, 2017, 5:21 AM EST
Rafnas T PRank #280 · 8.8K reputationPosted Jan 30, 2017, 11:52 PM EST