Cannot connect to remote mail server for sending emails in ASP.NET

emailsmtpwindows-server-2008

I want to migrate a web application from a Windows Server 2003 to a Windows Server 2008 R2. All works fine except sending emails from the application.

If I configure the application to use the smtp server on "localhost" it works, but changing it to the "real" host name (e.g. mail.example.org) no mail is sent. The error message says, that the remote server needs a secure connection or smtp authentication. But since it works when using "localhost" instead of the host name I doubt that this is the problem.

Also it's unlikely a problem with the mail server, I also tried it with another one.

So for me it seems like the firewall is blocking the outgoing connection to the mail server. I tried to open port 25, but it still did not work. Maybe I just did it the wrong way.


Update:
For clarifying my setup:

  • I have a Windows Server 2008 R2 with hMailServer installed (set up for some of the hosted domains)
  • For the website I'm talking about I need to use an external mail server (totally different hosting provider)

Apparently I was a bit off the track. It seems like it works when using connecting to the local mail server either with the host name "localhost" or "mail.somedomain.com" (while somedomain.com is set up in my mail server). But when using the host name of the external mail server ("mail.externaldomain.com") it seems like it tries to connect to the local server again, although this domain is not set up in the mail server. Thanks to Evan Anderson for the tip to use telnet – why I have not thought of it myself?… 🙂

Note, the website www.externaldomain.com is hosted on my server but the DNS entries are maintained by the other hosting provider. "externaldomain.com" is the only entry which points to my server all other records (MX, subdomains) are pointing to the other server.

So I think the question is now, how do i bring my server to connect to the external mailserver. Do I have to configure this in my mail server or is it a windows server thing?

Best Answer

Sniff the traffic (with Wireshark or Microsoft Network Monitor) and see what's really happening. You can probably glean whether or not a TCP connection to the mail server is being made with a netstat -a -n 1 | find ":25" running in a window on your server while you attempt to send email, but I'd go the sniffer route and put it to bed.

Its highly possible that the SMTP server does need authentication. You should run an SMTP transaction with TELNET "by hand" just to see what's happening. (You really should know how to do SMTP transport via TELNET...) Doing this from your server will have the added benefit of proving that the Windows Firewall isn't blocking outbound SMTP connection attempts, too.

Look at the traffic on wire and get to the bottom of the problem, rather than poking at it with a stick.