我正在使用此代码通过 yahoo SMTP 服务器发送 SMTP 电子邮件,这是针对我正在编写的个人项目。
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 服务器,则不会发生这种情况。
这是异常和堆栈跟踪:
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:\dev\ARCSoftware.FTPProcessor\ConsoleApplication1\Program.cs:line 28
我知道问题不是环境问题,因为我可以使用 Outlook Express 将这些确切设置发送到同一台服务器。我想知道我是否需要发送证书或其他东西?
如果您或您认识的任何人对此有任何想法,我将不胜感激。