栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

c#发送邮件 邮箱不可用

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c#发送邮件 邮箱不可用

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.

On Yahoo side?

Code:

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.

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

Get a request token from Yahoo

Launch a Web browser and send the user to Yahoo to authorize your application and get an authorization key

Trade the authorization key for an access token

Store the access token somewhere and use it when logging in with SMTP

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.

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/960001.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号