简体   繁体   English

Windows Server2008:打开 smtp 端口不足以发送邮件吗?

[英]Windows Server2008: Is opening smtp port not enough for sending mail?

I have written a simple program in C# that sends mail notifications.我在 C# 中编写了一个发送邮件通知的简单程序。 It works great on Windows 7, but it fails on Server 2008.它在 Windows 7 上运行良好,但在 Server 2008 上失败。

I've read a bit about it, but I can't see what is keeping me from sending mail.我已经阅读了一些关于它的内容,但我看不出是什么阻止了我发送邮件。 I've opened port 587 (SSL port for Gmail) outgoing and ingoing (TCP) but still no luck.我已经打开了端口 587(Gmail 的 SSL 端口)传出和传入(TCP),但仍然没有运气。 I even opened the firewall for the whole program.我什至为整个程序打开了防火墙。 Are there specific settings in Windows Server that I should be aware of? Windows 服务器中是否有我应该注意的特定设置?

*Edit - No other firewalls than windows' own. *编辑 - 除了 windows 自己的防火墙之外,没有其他防火墙。

Stack trace:堆栈跟踪:

System.Net.Mail.SmtpException: Failure sending mail.
---> System.Net.WebException: Unable to connect to the remote server
---> System.Net.Sockets.SocketException: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full 74.125..:587
     at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
     at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
--- End of inner exception stack trace ---

EDIT: I found my answer: The problem was nothing to do with windows server.编辑:我找到了答案:问题与 windows 服务器无关。 It was because it could not connect to my database.这是因为它无法连接到我的数据库。 Silly me.傻我。 Earlier i got a connection error when not able to connect to database, but now all i got was weird error messages;早些时候我无法连接到数据库时出现连接错误,但现在我得到的只是奇怪的错误消息; one of which was posted here.其中之一张贴在这里。

Thanks for all help anyways.无论如何,感谢所有帮助。 Great to get help so quickly.这么快就得到帮助真是太好了。

The clue is in the exception and I doubt has anything to do with your firewall:线索是例外,我怀疑与您的防火墙有关:

System.Net.Sockets.SocketException: An operation on a socket could not be performed 
because the system lacked sufficient buffer space or because a queue was full

There is a Microsoft KB article that may be worth reviewing, it's for Windows 2003 but I'd investigate it all the same:有一篇 Microsoft KB 文章可能值得查看,它适用于 Windows 2003,但我还是会对其进行调查:

BUG: You receive a "The operation has timed-out" error message when you access a Web service or when you use the IPAddress class BUG:当您访问 Web 服务或使用 IPAddress class 时,您会收到“操作已超时”错误消息

It also looks like the issue can occur under Windows 2008 as well according to this article which although is about Windows EBS, the underlying cause appears to be the same (scroll right to the bottom of the page):根据这篇关于 Windows EBS 的文章,看起来问题也可能发生在 Windows 2008 下,但根本原因似乎是相同的(向右滚动到页面底部):

EBS Console crashes every 5-7 days EBS 控制台每 5-7 天崩溃一次

Basically it's possible for windows to run out of protocol bindings.基本上,windows 可能会耗尽协议绑定。 They describe a tool called enum.exe that will determine the number of protocol bindings present on your machine.他们描述了一个名为enum.exe的工具,它将确定您机器上存在的协议绑定的数量。

There is a related article on Stack Overflow here:这里有一篇关于 Stack Overflow 的相关文章:

Why am I getting this SocketException in my C# service? 为什么我的 C# 服务中出现此 SocketException?

Is it possible that the exception information provided will give you a clue as to what's wrong?提供的异常信息是否有可能为您提供有关问题所在的线索? That is:那是:

An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full 74.125..:587由于系统缺少足够的缓冲区空间或队列已满 74.125..:587 无法对套接字执行操作

See http://blogs.msdn.com/b/sql_protocols/archive/2009/03/09/understanding-the-error-an-operation-on-a-socket-could-not-be-performed-because-the-system-lacked-sufficient-buffer-space-or-because-a-queue-was-full.aspx .请参阅http://blogs.msdn.com/b/sql_protocols/archive/2009/03/09/understanding-the-error-an-operation-on-a-socket-could-not-be-performed-because-the -system-lacked-sufficient-buffer-space-or-because-a-queue-was-full.aspx

In .NET, it's quite possible that this would be caused by not disposing of your SmtpClient .在 .NET 中,这很可能是由于未处理您的SmtpClient引起的。

Try troubleshooting things first as problem may be somewhere else:-)首先尝试排除故障,因为问题可能在其他地方:-)

  1. Try disabling firewall and give it a go.尝试禁用防火墙并给它一个 go。 It may be something really different then firewall on Windows 2008 blocking your way它可能与 Windows 2008 上的防火墙完全不同
  2. Try running telnet yourSmtpServer 587 that you are trying to reach尝试运行您尝试访问的telnet yourSmtpServer 587

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM