Yahoo Mail的C#SMTP电子邮件发送代码失败但对其他服务器工作正常,任何人都可以帮忙吗?

Dav*_*ess 7 c# yahoo smtp smtpclient mailmessage

我正在使用此代码通过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);
Run Code Online (Sandbox Code Playgroud)

这是发送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
Run Code Online (Sandbox Code Playgroud)

我知道问题不是环境问题,因为我可以使用Outlook Express将这些确切的设置发送到同一台服务器.我想知道我是否需要发送证书或其他什么?

如果您或您认识的任何人对此有任何想法,我将非常感谢您的帮助.

jac*_*ith 6

using System.Net.Mail;
using System.Net;

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void btn_Send_Click(object sender, RoutedEventArgs e)
    {
        MailMessage oMail = new MailMessage(new MailAddress("username@yahoo.com"), new MailAddress("username@yahoo.com"));
        SmtpClient oSmtp = new SmtpClient();
        oSmtp.Host = "smtp.mail.yahoo.com";
        oSmtp.Credentials = new NetworkCredential("username", "password");
        oSmtp.EnableSsl = false;
        oSmtp.Port = 587;
        oSmtp.Send(oMail);
    }
}
Run Code Online (Sandbox Code Playgroud)


sta*_*tto 3

465 不支持它,但以下帖子详细介绍了解决方法

如何使用 .NET Framework 通过 SSL SMTP 发送电子邮件?

更新:此链接详细说明了为什么它可以通过 Outlook Express 工作,但不能通过 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