System.Net.Mail.SmtpException:'邮箱不可用.服务器响应为:未执行请求的邮件操作:邮箱不可用' [英] System.Net.Mail.SmtpException: 'Mailbox unavailable. The server response was: Requested mail action not taken: mailbox unavailable'

查看:1186
本文介绍了System.Net.Mail.SmtpException:'邮箱不可用.服务器响应为:未执行请求的邮件操作:邮箱不可用'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Yahoo更改了用户身份验证,因此我收到此消息. 如果我使用Yahoo建议的选项,则我的代码仍然有效:

I am getting this message since Yahoo have made changes in user authentication. My code still works if I use option suggested by Yahoo, which is:

切换应用程序或更新应用程序时,您可以将旧应用程序提供给 临时访问.请记住,这不是永久性的 访问权限,然后您需要将其关闭.启用允许应用 使用安全性较低的登录帐户.启用该功能后,您将 会定期收到提醒您将其关闭的警报...

While you switch apps or update your app, you can give the old app temporary access. Just remember, this is not intended for permanent access and you'll want to turn it off afterwards. Turn on Allow apps that use less secure sign in. Once the feature is turned on, you'll get regular alerts reminding you to turn it off...

我的问题是如何在不打开

My question is how to update my code to work without turning on

允许使用安全性较低的应用登录.

Allow apps that use less secure sign in.

在Yahoo方面?

代码:

private void Test_Click(object sender, EventArgs e)
{
    MailMessage mail = new MailMessage("userid@yahoo.com", "user@example.com", "Test", "Hello World");

    SmtpClient smtp = new SmtpClient();
    smtp.UseDefaultCredentials = false;
    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.EnableSsl = true;
    smtp.Host = "smtp.mail.yahoo.com"; 
    smtp.Port = 587;//I tried 465 as well
    smtp.Credentials = new NetworkCredential( "userid@yahoo.com", "myPassword");

    smtp.Send(mail);
}

推荐答案

为避免使用该选项,您需要使用

To avoid using that option you would need to use OAuth2 for authentication instead of a user ID and password.

您需要在Yahoo中注册您的应用.然后完成OAuth2工作流程:

You would need to register your application with Yahoo. Then go through the OAuth2 workflow:

  • 从Yahoo获取请求令牌
  • 启动Web浏览器并将用户发送到Yahoo以授权您的应用程序并获取授权密钥
  • 将授权密钥换成访问令牌
  • 将访问令牌存储在某个地方,并在通过SMTP登录时使用它

您将为此需要第三方库.我认为SmtpClient不支持OAuth,您需要一个库来为您处理其他OAuth详细信息.

You're going to want third-party libraries for this. I don't think SmtpClient supports OAuth, and you'll want a library to handle the other OAuth details for you.

此处是如何通过以下方式进行OAuth的示例MailBee.Net(商业电子邮件库).

Here is an example of how to the OAuth this with MailBee.Net (a commercial e-mail library).

这篇关于System.Net.Mail.SmtpException:'邮箱不可用.服务器响应为:未执行请求的邮件操作:邮箱不可用'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆