“无法从传输连接读取数据:net_io_connectionclosed。” – Windows Vista Business和SMTP

无法在Windows Vista Business中testing从.NET代码发送电子邮件。

我正在编写代码,一旦certificate它将转移到SSIS包。 代码是通过电子邮件发送一个错误消息到收件人列表。

代码如下,但是当我执行代码时,我得到一个exception。

我创build了一个简单的类来完成邮件…devise可能会更好,我在实现更强大的function,方法等之前正在testingfunction。

namespace LabDemos { class Program { static void Main(string[] args) { Mailer m = new Mailer(); m.test(); } } } namespace LabDemos { class MyMailer { List<string> _to = new List<string>(); List<string> _cc = new List<string>(); List<string> _bcc = new List<string>(); String _msgFrom = ""; String _msgSubject = ""; String _msgBody = ""; public void test(){ //create the mail message MailMessage mail = new MailMessage(); //set the addresses mail.From = new MailAddress("me@domain.com"); //set the content mail.Subject = "This is an email"; mail.Body = "this is a sample body"; mail.IsBodyHtml = false; //send the message SmtpClient smtp = new SmtpClient(); smtp.Host = "emailservername"; smtp.Port = 25; smtp.UseDefaultCredentials = true; smtp.Send(mail); } } 

exception消息

 Inner Exception {"Unable to read data from the transport connection: net_io_connectionclosed."} Stack Trace " at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)\r\n at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)\r\n at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)\r\n at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)\r\n at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)\r\n at System.Net.Mail.SmtpClient.GetConnection()\r\n at System.Net.Mail.SmtpClient.Send(MailMessage message)" Outer Exception System.Net.Mail.SmtpException was unhandled Message="Failure sending mail." Source="System" StackTrace: at System.Net.Mail.SmtpClient.Send(MailMessage message) at LabDemos.Mailer.test() in C:\Users\username\Documents\Visual Studio 2008\Projects\LabDemos\LabDemos\Mailer.cs:line 40 at LabDemos.Program.Main(String[] args) in C:\Users\username\Documents\Visual Studio 2008\Projects\LabDemos\LabDemos\Program.cs:line 48 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel) at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData) at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext) at System.Activator.CreateInstance(ActivationContext activationContext) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: System.IO.IOException Message="Unable to read data from the transport connection: net_io_connectionclosed." Source="System" StackTrace: at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) InnerException: 

有几件事情可能会导致这个问题,这里是我发现的一些事情。 问题:你提到“交换” – 这是一个交换服务器? 主机是否需要authentication(也许你需要添加authentication到客户端)? 我会尝试做的第一个是分配主机到静态IP地址,而不是主机名,看看是否工作的第一。 如果确实如此,则很可能是DNS映射的问题。

如果使用虚拟化运行交换服务器,则需要将SmtpClientconfiguration为虚拟服务器的主机IP,而不是物理主机服务器名称或IP。 右键单击默认SMTP虚拟服务器,select属性,然后进入访问选项卡,单击中继,然后将发送SMTP请求的计算机的IP地址添加到SMTP服务器。 (ASP.net网站)

如果这不起作用,这是因为服务器阻止您发送SMTP数据包。 您需要确保将要发送SMTP邮件的框添加到SMTP服务器。 这是通过IIS的身份validation选项卡完成的。

我也想指出,你应该处理邮件客户端,或者在“使用”语句中使用客户端。 这将确保“QUIT”被发送到服务器并正常closures连接。

 using(SmtpClient smtp = new SmtpClient()) { smtp.Host = "emailservername"; smtp.Port = 25; smtp.UseDefaultCredentials = true; smtp.Send(mail) } 

重新启动IIS。 我知道这听起来很愚蠢,做一切的重启。 (对不起,碰到一个旧的线程)。 但有时重新启动IIS的作品神奇。 我面对完全相同的问题,并重新开始解决它。

可能发生的原因暂时“localhost”这个名字无法解决。 我只是在这里张贴,所以现在面临的人可能会尝试这个快速修复,然后再尝试进一步调查。 希望能帮助到你

如果您在SMTP服务设置中指定了IP地址,请确保您在IIS7中指定了该机器的IP地址,而不是放置localhost

IIS7可以很容易地select'localhost',但是如果IP实例是10.0.0.1,那么会导致这个错误

如果您在IIS 7中使用本地主机(使用本地主机),则将其更改为本机的IP地址而不是本地主机或127.0.0.1

也请按照下面的链接相应地更新您的邮件服务器中继:

信箱不可用。 服务器响应是:5.7.1无法中继abc@xyz.com

Vista和Windows 7没有任何SMTP服务器,这个工具从Windows XP以后就被删除了,所以你需要明确地设置你的SMTP服务器,有几个工具可以在市场上买到,你可以检查一下。 另外,一旦configuration了SMTP,请记住检查您将用于发送电子邮件的服务器名称。

我有同样的问题,因为我的服务器上有多个IP(虚拟服务器),我的主机指向本地主机,而我的SMTP虚拟服务器分配给一个特定的IP:

  <smtp deliveryMethod="Network"> <network host="localhost" port="25" defaultCredentials="false"/> </smtp> 

有两个解决scheme:

  1. 更改您的代码并将主机设置为由SMTP虚拟服务器而不是本地主机使用的特定IP。
  2. 将SMTP虚拟服务器IP更改为全部未分配

要查看/更改SMTP虚拟服务器IP:右键单击默认SMTP虚拟服务器,select属性,在常规选项卡上更改/查看IP地址。

希望这可以挽救一个人的同一个问题。

我发现,Vista商业操作系统不附带IIS SMTP。 我怀疑这是谜题的缺失部分。 有没有人有这个问题的运气?

你的代码是不完整的.Dash在识别它是正确的。否则检查smtp组件是否安装或不检查链接文本

我最近6个小时面对这个问题,我是新的,所以我试图通过以下方式来解决这个问题

1)我打开命令提示符(例如Ctrl + R键入cmd并回车)。
2)检查SMTP服务器ping并检查响应。
3)如果得到回应,那么没关系,并移动下一步4其他明智的smtp名称是错误的。
4)然后我通过telnet检查smtp端口(例如25)是否打开。
5)使用这个cmd我们检查SMTP响应。
6) telnet“yoursmtpname”“portno” (例如telnet smtp.gmail.com 25)
7)如果telnet不工作,请在控制面板上安装或添加新function。
8)如果它正在工作,那么它的传递结果就像。
9)220 mx.google.com ESMTP。

使用上述步骤,我们可以发现smtp连接已准备好或不发送邮件。

我使用.NET Framework v4.5在VB中开发了一个Windows服务应用程序,最近遇到了这个问题。

首先,有一点背景 – 我试图处理错误“服务不可用,closures传输通道。服务器响应是:错误:一个会话中消息太多”,通过调用Dispose方法解决在发送每封电子邮件之后在SmtpClient对象上。 为了超级安全,我还在MailMessage对象上调用了Dispose。

好吧,现在“一个会话中的消息太多”问题得到了解决,但现在我偶尔得到了“无法从传输连接读取数据:net_io_connectionclosed”错误。 真棒。 事实certificate,我并没有始终如一地执行我的电子邮件课程 – 有一次,这个课程正在处理,而另一个则不是。

下面是一个解决这两个问题的例子(这是在VB中,但你明白了):

 With New clsEmail(True) With .Message .To.Add("user@domain.com") .Subject = msgSubject .Body = msgContents End With .Server.Send(.Message) .Server.Dispose() .Message.Dispose() End With 

我的电子邮件类除了别的以外,还有2个属性 – 消息(System.Net.Mail.MailMessage)和服务器(System.Net.Mail.SmtpClient),这是在这个例子中被部署的东西。

每次在我的服务中发送电子邮件的每个实例都以这种方式实现后,我还没有遇到过几百封电子邮件中的单个问题。

升级到.NET 4.0并应用所有安全更新