tags:

views:

567

answers:

3

I've got code as follows:

var smtpClient = new SmtpClient("my.mail.server");
smtpClient.Send(mailmessage);

however the send method call fails with a "the remote machine actively refused" exception message. I know that there's no firewall blocking cuz I can telnet to the same addresse and manually work the Smtp protocol through with the server. I know the code is working cuz I can get a connection to a different port than the default 25. There's no software firewall blocking the transmission.

When wiresharking I can see the packages being set when telnet'ing and I can see that nothing leaves my machine when I try with the code. So it's a safe assumption that the problem is on my machine and has nothing to do with the network.

Basically I can connect to the address with everything else than .NET code which leads me to my problem potentially being a configuration problem but I lack ideas of where and what I'd need to configure differently. Any suggestions to a possible cause?

EDIT: In a project with only the two line that sends the mail I get the same problem. When trying to establish a TCP connection through code I get the same problem so I know it's nothing to do with the SMTP protocol (or authentication) the problem is the TCP socket connection attempt being blocked but I still have no clue why

+1  A: 

Have you checked the configuration of the SMTP server? It could be configured to not allow anonymous connections or to deny your IP address.

Can you send an email through the SMTP server using another client e.g. Outlook?

David G
:) As I said I can connect to the Smtp server via telnet. ANd what I didn't mention the server is not asking for any kind of credentials and I can connect with basically anything but my .NET code. (I can connect to a different server running on the same machine on adifferent port with the same code so I know the code is working)
Rune FS
+1  A: 

What OS are you running? I'll now state the obvious and ask if you have verified that Windows Firewall is off?(I see your software firewall comment but this tends to get overlooked)

Also try and verify the port being used as we have to use ours like so -->

SmtpClient smtpClient = new SmtpClient("OURMAIL",25);
smtpClient.Send(message);

Exchange Ports

Refracted Paladin
I didn't see your comments below DaveG's answer....hmm.
Refracted Paladin
+1  A: 

Well It would seem the system administrators had forgotten that they had put too firewalls in place... (only costed me two days or so) when it comes to port 25 our antivirus also includes antispam. Thanks for the thoughts and suggestions everyone

Rune FS