Harsh kantharia Harsh kantharia - 20 days ago 9
C# Question

authentication error in sending mail from yahoo in c# windows application

i am trying to send email from my software using the smtp of yahoo but it shows the following error
"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Authentication required".

I know about the less secure apps setting in google but i don't know about the settings in yahoo. the same code runs fine with the gmail account credentials. here is the code for reference.

string EmailFrom = "test@yahoo.com";
string EmailTo = "test@gmail.com";
string PassWord = "test123";
string EmailHost = "smtp.mail.yahoo.com";
string status = "";
string Body = "";

MailMessage message = new MailMessage();
SmtpClient smtp = new SmtpClient();

message.From = new MailAddress(EmailFrom);
message.To.Add(new MailAddress(EmailTo));
message.Subject = "Auto Backup at test" ;
message.Body = "Backup has been taken at test on" + DateTime.Now;
Body = "Backup has been taken at test on" + DateTime.Now;
smtp.Port = 587;
smtp.Host = EmailHost;
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(EmailFrom, PassWord);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
//ServiceLogLibrary.WriteErrorlog("Step:5");
//Library.WriteErrorlog("Before sending mail");
smtp.Send(message);

Answer

You need to go to

  1. Go to your "Account security" settings.
  2. Select Allow apps that use less secure sign in.
  3. To deny or turn off app access, deselect the undesired app.

Source:Temporarily allow or deny access to apps using older security sign in

[Screenshot]

Comments