Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

Sending message using MailMessage, working fine in localhost but after uploading on Server giving error as given below.

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. Learn 
more at


What I have tried:

Using following code and i've also set
Less secure app access: ON in google


using (MailMessage emailMessage = new MailMessage())
                {
                    emailMessage.From = new MailAddress(_mailConfig.Value.FromEmail, _mailConfig.Value.FromName);
                    emailMessage.To.Add(new MailAddress(to));
                    emailMessage.Subject = subject;
                    emailMessage.Body = emailBody;
                    emailMessage.IsBodyHtml = true;
                    emailMessage.BodyEncoding = Encoding.UTF8;
                    emailMessage.Priority = MailPriority.Normal;
                    using (SmtpClient MailClient = new SmtpClient("smtp.gmail.com", 587))
                    {
                        MailClient.UseDefaultCredentials = false;
                        MailClient.EnableSsl = true;                        
                        MailClient.Credentials = new System.Net.NetworkCredential("test@gmail.com", "password");
                        MailClient.Send(emailMessage);
                    }
                }
Posted
Updated 20-Sep-21 19:54pm
v2

1 solution

Try to turn Off 2-Step Verification in Gmail.
 
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