title: sending email (Gmail) in asp.net
body: <p>I was trying to send <code>email</code> using <code>gmail account</code> on asp.net c#, but I keep getting this error:</p>
  
  <blockquote>
    <p>A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond [2607:f8b0:400c:c01::6c]:587</p>
  </blockquote>
  
  <p>I have tried different codes from different resources,but none of them worked with my project
  More over I've tried those steps but still not working:</p>
  
  <ol>
  <li>trying ports 25, 465, 587 on both VS 2012 server and localhost (iis    7).</li>
  <li>Firewall set to off , antivirus set to off.</li>
  <li>starting visual studio as administrator.</li>
  </ol>
  
  <p>Please , can anyone tell me what is the reason behind this error. and if there is possibility to change something , where should I start..</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  
  public partial class Default6 : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          var myMailMessage = new System.Net.Mail.MailMessage();
          myMailMessage.From = new System.Net.Mail.MailAddress("serveremail@gmail.com");
          myMailMessage.To.Add("youremail@yahoo.com");// Mail would be sent to this address
          myMailMessage.Subject = "Feedback Form";
          myMailMessage.Body = "Hello";
  
          var smtpServer = new System.Net.Mail.SmtpClient("smtp.gmail.com");
          smtpServer.Port =587;
          smtpServer.Credentials = new System.Net.NetworkCredential("serveremail@gmail.com", "**YOURPASSWORD**");
          smtpServer.EnableSsl = true;
          smtpServer.Send(MyMailMessage);
  
          Response.Redirect("Default.aspx");
      }
  }
  </code></pre>