title: ASP.NET cannot sent email from smtp
body: <p><a href="https://stackoverflow.com/questions/51834750/asp-net-smtp-gmail-failed">back to my previous question</a>. I am still have problem with sending email by Gmail SMTP. Previously i had error that:</p>
  
  <blockquote>
    <p>Failure sending mail.</p>
  </blockquote>
  
  <p>But now i changed some code and now i have his 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 64.233.167.109:465  </p>
  </blockquote>
  
  <p>I was so pissed off, that I started using wireshark to understand where the problem.</p>
  
  <p>Here is what i found:</p>
  
  <blockquote>
    <blockquote>
      <p>smtp.gmail.com Server:         53.90.35.60 Address:        53.90.35.60#53</p>
    </blockquote>
    
    <p>Non-authoritative answer: smtp.gmail.com  canonical name =
    gmail-smtp-msa.l.google.com. Name:   gmail-smtp-msa.L.google.com
    Address: 64.233.167.108 Name:   gmail-smtp-msa.L.google.com Address:
    64.233.167.109</p>
  </blockquote>
  
  <p>so as I understand there is response received from mail smtp server</p>
  
  <p>Also we use proxy in our intranet, but I added proxy in my application, inside Web.config:</p>
  
  <pre><code>&lt;system.net&gt;
  &lt;defaultProxy enabled="true"&gt;
    &lt;proxy proxyaddress="proxy_was_here" bypassonlocal="true"
    /&gt;
  &lt;/defaultProxy&gt;
  </code></pre>
  
  <p></p>
  
  <p>and here is the part of new code:</p>
  
  <pre><code>var fromAddress = new MailAddress("email", "From Name");
                      var toAddress = new MailAddress("email", "To Name");
                      const string fromPassword = "pass";
                      const string subject = "Subject";
                      const string body = "Body";
  
                      var smtp = new SmtpClient
                      {
                          Host = "smtp.gmail.com",
                          Port = 465,
                          EnableSsl = true,
                          DeliveryMethod = SmtpDeliveryMethod.Network,
                          UseDefaultCredentials = false,
                          Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
                      };
                      using (var message = new MailMessage(fromAddress, toAddress)
                      {
                          Subject = subject,
                          Body = body
                      })
                      {
                          smtp.Send(message);
                      }
  </code></pre>
  
  <p>If you have any questions, please look at my previous question or just write in the comments below.</p>