C#中的SMTP电子邮件发送代码失败,雅虎邮箱,但为其他服务器工作正常,谁能帮助? [英] C# SMTP email sending code fails for Yahoo Mail but works fine for other servers, can anyone help?

查看:305
本文介绍了C#中的SMTP电子邮件发送代码失败,雅虎邮箱,但为其他服务器工作正常,谁能帮助?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个代码通过雅虎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:\dev\ARCSoftware.FTPProcessor\ConsoleApplication1\Program.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

我如何通过SSL发送电子邮件与.NET Framework 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-要进行身份验证,对多端口465.aspx

这篇关于C#中的SMTP电子邮件发送代码失败,雅虎邮箱,但为其他服务器工作正常,谁能帮助?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆