Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
After running the following code a message show"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. "What is the solution.please help

C#
connection.Open();
               OleDbCommand command1 = new OleDbCommand();
               command1.Connection = connection;
               string cq = "Select Email From student where S_ID in(select S_ID FROM studentbook where DateDiff('d',[Issue_Date], NOW())=31) ";
                command1.CommandText = cq;
                OleDbDataAdapter da1 = new OleDbDataAdapter(command1);
                DataTable dt1 = new DataTable();
                da1.Fill(dt1);
               foreach (DataRow row in dt1.Rows)
               {
                   string email = row["Email"].ToString();
                   MessageBox.Show("Trying to send email ");

                   using (MailMessage mm = new MailMessage("sujitcsecuet@gmail.com", email))
                   {
                       mm.Subject = "Attention please,renew your book";
                       mm.Body = string.Format("1 month over,you should renew or return the book");

                       mm.IsBodyHtml = true;
                       SmtpClient smtp = new SmtpClient();
                       smtp.Host = "smtp.gmail.com";
                       smtp.EnableSsl = true;
                       System.Net.NetworkCredential credentials = new System.Net.NetworkCredential();
                       credentials.UserName ="xxxxxxx";
                       credentials.Password = "xxxxxx";
                       smtp.UseDefaultCredentials = true;
                       smtp.Credentials = credentials;
                       smtp.Port = 587;
                       smtp.Send(mm);
                       MessageBox.Show("Email sent successfully");
                   }
               }
Posted
Updated 29-Aug-15 20:40pm
v5
Comments
F-ES Sitecore 29-Aug-15 16:39pm    
This is asked daily, google the error message. Ultimately you shouldn't send email via gmail though.
Manfred Rudolf Bihy 29-Aug-15 16:58pm    
Don't post your credentials please. That will open your account to all kinds of abuse. Please change your password as quickly as possible.
Member 11832549 30-Aug-15 2:32am    
thanks.i forgot remove that two lines.now i change my account password.
Aravindba 29-Aug-15 22:11pm    
you already give true for SSL and UseDefaultCredentials ,also u give username and password,i think in ur gamil account u need to enable some setting for send mail.
https://www.google.com/#q=The+SMTP+server+requires+a+secure+connection+or+the+client+was+not+authenticated.+The+server+response+was:+5.5.1+Authentication+Required
Member 11832549 30-Aug-15 3:51am    
after change the setting message show"email sent successfully" but checking mail account didn't found any mail.

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