3
votes

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
According to their FAQ, gmail's SMTP SSL port is 465 (587 is the TLS port). Maybe that's the problem?Frédéric Hamidi
Due you run the program as normal application or is it running as a Service?Oliver
Do you receive an error in code when trying to send? If so, can you include a stack trace?Tom Studee
Sorry for late answer. Two exams in a row. To Frédéric Hamidi: The port is not the problem as it works in windows 7. Yes, googles pages says 465 for ssl and another one mentioned is 587 and it works great with ssl enabled. Oliver: Running program as a normal application. There should not be a difference between service and normal program when it comes to firewall forwarding? The stack trace is nothing more than standard exception when not able to connect to smtp-server. Can give stack trace later if this would help.stackman
I've forwarded a lot of programs through the firewall before without a hassle. Most of them home made. Is there something special about forwarding ports for mail sending? Some built in services in server 2008 that uses those ports or blocks them?stackman

3 Answers

2
votes

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:

BUG: You receive a "The operation has timed-out" error message when you access a Web service or when you use the 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):

EBS Console crashes every 5-7 days

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:

Why am I getting this SocketException in my C# service?

1
votes

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

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.

0
votes

Try troubleshooting things first as problem may be somewhere else :-)

  1. Try disabling firewall and give it a go. It may be something really different then firewall on Windows 2008 blocking your way
  2. Try running telnet yourSmtpServer 587 that you are trying to reach