Problems in sending Email using hostname smtp.gmail.com in C#
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail">Sending email in .NET through Gmail</a>  </p>
</blockquote>



<p>I am facing the issue of Network timed out while sending the email using the C# program </p>

<p>My code is </p>

<pre><code>protected void sendEmail(String m_RecipentTo)
{
    MailMessage mailMessage = new MailMessage();
    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
    mailMessage.To.Add(m_RecipentTo);
    mailMessage.Subject = m_Subject;
    mailMessage.Body = m_Body;
    mailMessage.From =  new MailAddress(m_SenderEmail);
    SmtpServer.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
    SmtpServer.Port = 465;
    SmtpServer.EnableSsl = true;
    SmtpServer.Credentials = new System.Net.NetworkCredential(username, password);
    SmtpServer.Send(mailMessage);
}
</code></pre>

<h2>I tried using the port number 587 it gives</h2>

<p>An attempt was made to access a socket in a way forbidden by its access permissions 74.125.25.108:587. </p>

<p>I have added the port under Filewall settings -> inbound Rule -> Port</p>
