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
4 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Rafnas T PPosted Jan 31, 2017, 4:52 AM
Nilesh ShahPosted Jan 24, 2017, 10:55 AM
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 GuptaPosted Jan 24, 2017, 10:22 AM
Francis SusaimichaelPosted Jan 24, 2017, 10:21 AM