ASP.NET - SmtpClient - Unable to connect to the remote server ASP.NET - SmtpClient - Unable to connect to the remote server asp.net asp.net

ASP.NET - SmtpClient - Unable to connect to the remote server


The "Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it" error usually means that the TCP port you are trying to connect to does not have any service listening on it, i.e. it is closed and a tcp connection could not be made, let alone a SMTP connection.

Nothing will show in your exchange logs as it is failing at a lower level in the network stack and your mail server will not even see the connection attempt.

Can you post the .net1.1 code as well? The most likely problem is that the server is listening on a non standard port and you are not specifying that port in the new code. Please note that you need to set the port by using the Port property, you cannot simply append it to the Host property, e.g.

Wrong:

client.Host = "mail.someco.com:10000";

Correct:

client.Host = "mail.someco.com";client.Port = 10000;


If you are using any antivirus software check it's log to see whether it is because of the antivirus. I faced same problem when McAffee was blocking my mails (there is a security policy - Prevent mass mailing worms from sending mails). Edit this policy and add your application to the exception list. In my case this sorted the problem. Please check if it works for you.


You are sure the SmtpServer property of the System.Web.Mail.SmtpMail is set in the old code? It was possible to use it without setting this property and then it used the local server's SMTP service. System.Web.Mail.SmtpMail.SmtpServer