Open a command prompt on your server and type somthing like this:
telnet name.of.your.mailserver 25
If the connection fails you can't reach your mail server from the server your application runs on. Likewise typing this:
nslookup name.of.your.mailserver
will tell you if your server can resolve the mailservers name to an IP address. Try these commands and tell me in a comment to my answer what results you received. You shouldn't tell me any IP addresses though just comment if nslookup command was able to resolve the name.
Best Regards,
Manfred