SmtpClient sends mail from windows application but fails in ASP.NET / MVC
<p>Hi I am getting a funny error. I am able to send email if I use windows application but the same code when run as part of ASP.NET / MVC application throws SendMessage error saying - <code>System.Net.Mail.SmtpException: Failure sending mail. ---&gt; System.Net.WebException: Unable to connect to the remote server ---&gt; System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions</code></p>

<p>The code I am using is: </p>

<pre><code> using (MailMessage message = new MailMessage("from@my.com", "t0@my.com"))
                {
                    message.CC.Add("cc@my.com");
                    message.IsBodyHtml = true;
                    message.Subject = "Test subject");
                    message.Body = "Test Body";
                    SmtpClient client = new SmtpClient();
                    client.Host = "abc.com";
                    client.Port = 25;
                    client.Send(message);
                }
</code></pre>

<p>Can someone suggest what is wrong here. </p>

<p>Thanks,
A</p>