C# SMTP email sending code fails for Yahoo Mail but works fine for other servers, can anyone help?(雅虎邮箱的 C# SMTP 电子邮件发送代码失败,但适用于其他服务器,有人可以帮忙吗?)
问题描述
我正在使用此代码通过 yahoo SMTP 服务器发送 SMTP 电子邮件,这是我正在编写的个人项目.
I am using this code to send an SMTP email via the yahoo SMTP server, it is for a personal project I am writing.
using System.Net.Mail;
using System.Net;
SmtpClient theClient = new SmtpClient("smtp.mail.yahoo.com", 465);
theClient.UseDefaultCredentials = false;
theClient.Credentials = new NetworkCredential("username", "password");
theClient.EnableSsl = true;
MailMessage theMessage = new MailMessage("username@yahoo.com",
"to.someone@gmail.com");
theMessage.Subject = "Dave test from C# subject";
theMessage.Body = "Dave test from C# body";
theClient.Send(theMessage);
这都是发送 SMTP 电子邮件的标准代码,但是……服务器似乎抛出了一个错误.它强行终止连接.如果我使用其他 SMTP 服务器(如 Gmail、Windows Live 或各种其他 ISP Smtp 服务器),则不会发生这种情况.
It's all pretty standard code for sending SMTP email, but... the server seems to throw an error. It forcibly terminates the connection. This does not happen if I use other SMTP servers like Gmail, Windows Live or various other ISP Smtp servers.
这是异常和堆栈跟踪:
System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at ConsoleApplication1.Program.Main(String[] args) in E:devARCSoftware.FTPProcessorConsoleApplication1Program.cs:line 28
我知道问题不是环境问题,因为我可以使用 Outlook Express 将这些确切设置发送到同一台服务器.我想知道我是否需要发送证书或其他什么?
I know the problem is not environmental though as I can send to the same server with these exact settings using Outlook Express. I am wondering if I need to send a certificate or something?
如果您或您认识的任何人对此有任何想法,我将不胜感激.
If you, or anyone you know where has any ideas about this I would greatly appreciate some help.
推荐答案
465不支持,但是下面的帖子详细介绍了一个解决方法
It's not supported through 465, but the following post details a workaround
我如何发送电子邮件通过带有 .NET Framework 的 SSL SMTP?
更新:此链接详细说明了为什么它可以通过 Outlook Express 工作,但不能通过 System.Net.Mail
UPDATE: This link details why it might work through Outlook Express, but not through the System.Net.Mail
http://blogs.msdn.com/b/webdav_101/archive/2008/06/02/system-net-mail-with-ssl-to-authenticate-against-port-465.aspx
这篇关于雅虎邮箱的 C# SMTP 电子邮件发送代码失败,但适用于其他服务器,有人可以帮忙吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:雅虎邮箱的 C# SMTP 电子邮件发送代码失败,但适用于其他服务器,有人可以帮忙吗?


- C#MongoDB使用Builders查找派生对象 2022-09-04
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01