在 c# windows 应用程序中从雅虎发送邮件时出现身份验证错误 [英] authentication error in sending mail from yahoo in c# windows application
问题描述
我正在尝试使用 yahoo 的 smtp 从我的软件发送电子邮件,但它显示以下错误SMTP 服务器需要安全连接或客户端未通过身份验证.服务器响应为:5.7.1 需要身份验证".
我知道 google 中安全性较低的应用程序设置,但我不知道 yahoo 中的设置.相同的代码使用 gmail 帐户凭据运行良好.这是代码供参考.
string EmailFrom = "test@yahoo.com";string EmailTo = "test@gmail.com";字符串密码 = "test123";string EmailHost = "smtp.mail.yahoo.com";字符串状态 = "";字符串正文 = "";MailMessage 消息 = new MailMessage();SmtpClient smtp = 新 SmtpClient();message.From = new MailAddress(EmailFrom);message.To.Add(new MailAddress(EmailTo));message.Subject = "测试时自动备份";message.Body = "已在测试时进行备份" + DateTime.Now;Body = "已在测试时进行备份" + 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("发送邮件前");smtp.Send(message);
你需要去
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);
解决方案You need to go to
- Go to your "Account security" settings.
- Select Allow apps that use less secure sign in.
- To deny or turn off app access, deselect the undesired app.
Source:Temporarily allow or deny access to apps using older security sign in
这篇关于在 c# windows 应用程序中从雅虎发送邮件时出现身份验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!