Actively refused connections
Recently I was using the System.Net.Mail namespace to send out email messages from a simple .net application. I was receiving an error which boiled down to “the server is actively refusing the connection.”
This message is not particularly helpful. If you run into this issue you might want to check that your mail server will allow SMTP relays. My server was set to allow SMTP relays – yet I was still getting the issue.
I found a Microsoft tool called SMTPDiag (for use with Exchange server) that runs through the network performing various test to find out why SMTP is not working.
I ended up failing on one of the final steps – connecting to the exchange server.
netstat -n -a
on the server and found that port 25 was open and listening.
Then on my client machine I tried to create the simplest connection I could to the server:
telnet [mailServer] 25
This refused to connect as well.
I checked the firewall to see if port 25 was blocked in some way and it was not.
I was basically flabbergasted and about to give up when my anti-virus program popped up to do an update. A light bulb went off in my head.
CHECK YOUR ANTI-VIRUS SETTINGS WHEN HAVING CONNECTION PROBLEMS!
McAffee ANtiVirus was blocking all outgoing traffic over port 25 on my machine. I didn’t even think about anti-virus blocking ports, but it is quite common, especially with mail ports. I felt like an idiot, but I decided to share my experience to help others out there.
PS – SMTPDiag is quite useful, and Marc Grote has a good tutorial on it.