Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i am facing the following problem
The SMTP server requires a secure connection or the client was not authenticated
although i do low secrure in Google Account
Username and password is Correct but invain when i host the application on Somee.com Server Please Push you help please

What I have tried:

protected void btPassRec_Click(object sender, EventArgs e)
       {
           BusinessObject_Layer.BO_Layer objbo = new BusinessObject_Layer.BO_Layer();
           objbo.Email = tbEmailId.Text;
           DataTable dt = BSS.SelectEmailAddress(objbo);
           if (dt.Rows.Count != 0)
           {
               String myGUID = Guid.NewGuid().ToString();
               int Uid = Convert.ToInt32(dt.Rows[0][0]);
               BusinessObject_Layer.BO_Layer objbos = new BusinessObject_Layer.BO_Layer();
               objbos.GUIDID = Guid.Parse(myGUID.ToString());
               objbos.UID = Uid;
               BSS.InsertForgottenPassowrd(objbos);

               //send email
               String ToEmailAddress = dt.Rows[0][3].ToString();
               String Username = dt.Rows[0][1].ToString();
               String EmailBody = "Hi " + Username + ",<br/><br/> Click the link below to reset your password <br/><br/> http://localhost:60219/Reset_PassU.aspx?Uid=" + myGUID;
               MailMessage PassRecMail = new MailMessage("<removed>", ToEmailAddress);
               PassRecMail.Body = EmailBody;
               PassRecMail.IsBodyHtml = true;
               PassRecMail.Subject = "Reset Password";



               SmtpClient SMTP = new SmtpClient("smtp.gmail.com", 587);
               SMTP.Credentials = new NetworkCredential()
               {
                   UserName = "<removed>",
                   Password = "p@ssw0rd-r3m0v3d"
               };
               SMTP.EnableSsl = true;

               SMTP.Send(PassRecMail);
               SMTP.UseDefaultCredentials = false;
               lblPassRec.Text = "Check your email to reset your password.";
               lblPassRec.ForeColor = Color.Green;

           }
           else
           {
               lblPassRec.Text = "OOps This email id DOES NOT exist in our database !";
               lblPassRec.ForeColor = Color.Red;
           }
Posted
Updated 2-Sep-20 3:05am
v2
Comments
Afzaal Ahmad Zeeshan 2-Sep-20 8:57am    
Can you try with the port 25 first?

1 solution

Google for how to send email through gmail, this is very well documented and every problem you will face (and there will be many) has already been answered. One issue I see is that you set UseDefaultCredentials to false after you've supplied the credentials. I know it sounds weird but SmtpClient class is not well written :) you need to set UseDefaultCredentials to false before setting the credentials themselves (you're also setting it after calling .Send).

C#
SMTP.UseDefaultCredentials = false;
SMTP.Credentials = new NetworkCredential()
{
    UserName = "<removed>",
    Password = "p@ssw0rd-r3m0v3d"
};
SMTP.EnableSsl = true;

SMTP.Send(PassRecMail);


There may well be other issues, eg you have to configure your gmail account to allow people to send programmatically, you might be using a different "from" address to the credentials you supply. Whatever it is, sending through gmail is an incredibly frequently asked question so just google for the code and config required.

My advice, though, is to simply not send through gmail at all, send through your webhost's SMTP server instead, and for local testing use your network's SMTP server or use something like smtp4dev.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900