问题描述
我正在使用此代码通过 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 电子邮件发送代码失败,但适用于其他服务器,有人可以帮忙吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)