我用 C# 编写了一个发送邮件通知的简单程序。它在 Windows 7 上工作得很好,但在 Server 2008 上却失败了。
我读过一些相关内容,但我不明白是什么阻止了我发送邮件。我已经打开端口 587(Gmail 的 SSL 端口)传出和传入 (TCP),但仍然没有运气。我什至为整个程序打开了防火墙。 Windows Server 中是否有我应该注意的特定设置?
*编辑-除了Windows自己的防火墙之外没有其他防火墙。
堆栈跟踪:
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 ---
编辑:我找到了答案:问题与 Windows 服务器无关。这是因为它无法连接到我的数据库。愚蠢的我。早些时候,当无法连接到数据库时,我收到了连接错误,但现在我收到的只是奇怪的错误消息;其中一篇已发布在这里。
无论如何,感谢所有帮助!这么快就得到帮助真是太好了。
I have written a simple program in C# that sends mail notifications. It works great on Windows 7, but it fails on 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. I even opened the firewall for the whole program. Are there specific settings in Windows Server that I should be aware of?
*Edit - No other firewalls than windows' own.
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. 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.
发布评论
评论(3)
线索就在例外中,我怀疑与您的防火墙有什么关系:
有一篇 Microsoft 知识库文章可能值得回顾,它适用于 Windows 2003,但我仍然会调查它:
根据这篇文章,该问题似乎也可能发生在 Windows 2008 下,尽管该文章是关于 Windows EBS 的,但根本原因似乎是相同的(向右滚动到该文章的底部) 页):
基本上 Windows 可能会耗尽协议绑定。他们描述了一个名为
enum.exe
的工具,该工具将确定您的计算机上存在的协议绑定的数量。Stack Overflow 上有一篇相关文章:
The clue is in the exception and I doubt has anything to do with your firewall:
There is a Microsoft KB article that may be worth reviewing, it's for Windows 2003 but I'd investigate it all the same:
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):
Basically it's possible for windows to run out of protocol bindings. They describe a tool called
enum.exe
that will determine the number of protocol bindings present on your machine.There is a related article on Stack Overflow here:
提供的异常信息是否有可能为您提供有关问题所在的线索?那是:
请参阅 http://blogs.msdn.com/b/sql_protocols/archive/2009/03/09/understanding-the-error-an-operation-on-a-socket-could-not-be-执行是因为系统缺乏足够的缓冲区空间或因为队列已满.aspx。
在 .NET 中,这很可能是由于未处理
SmtpClient
造成的。Is it possible that the exception information provided will give you a clue as to what's wrong? That is:
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.
In .NET, it's quite possible that this would be caused by not disposing of your
SmtpClient
.首先尝试排除故障,因为问题可能出在其他地方:-)
telnet yourSmtpServer 587
Try troubleshooting things first as problem may be somewhere else :-)
telnet yourSmtpServer 587
that you are trying to reach