简体   繁体   English

在 c# windows 应用程序中从雅虎发送邮件时出现身份验证错误

[英]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".我正在尝试使用 yahoo 的 smtp 从我的软件发送电子邮件,但它显示以下错误“SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.7.1 需要身份验证”。

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.相同的代码使用 gmail 帐户凭据运行良好。 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);

Just providing some more information here as things have changed a little since the accepted answer was posted.仅在此处提供更多信息,因为自接受的答案发布以来,情况发生了一些变化。

  1. Go to the account security settings ( https://login.yahoo.com/account/security )转到帐户安全设置 ( https://login.yahoo.com/account/security )
  2. Scroll to the bottom and search for the "Manage app passwords" heading as shown below and click it to add a new app.滚动到底部并搜索“管理应用程序密码”标题,如下所示,然后单击它以添加新应用程序。

在此处输入图片说明

  1. Select an app type and generate the password.选择应用程序类型并生成密码。 For API apps, use "Other App".对于 API 应用程序,请使用“其他应用程序”。

在此处输入图片说明

  1. Use this password instead of your standard mailbox password when sending emails via your SmtpClient.通过 SmtpClient 发送电子邮件时,请使用此密码而不是标准邮箱密码。

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来源:暂时允许或拒绝使用旧安全登录的应用程序访问

[截图]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM