title: Sending mail from gmail SMTP C# Connection Timeout
body: <p>I have been trying to send an email via C# from a gmail account for account registration for my website. </p>
  
  <p>I have tried several ways however the same exception continues to pop up: System.Net.Mail.Smtp Exception - Connection has timed out.</p>
  
  <p>This is what I inluded in my Web.config file:</p>
  
  <pre><code>&lt;system.net&gt;
      &lt;mailSettings&gt;
          &lt;smtp deliveryMethod="Network" 
                from="Writely &amp;lt;mrbk.writely@gmail.com&amp;gt;"&gt;
              &lt;network host="smtp.gmail.com" 
                       port="465" 
                       enableSsl="true" 
                       defaultCredentials="false" 
                       userName="mrbk.writely@gmail.com" 
                       password="******" /&gt;
          &lt;/smtp&gt;
      &lt;/mailSettings&gt;
  &lt;/system.net&gt;
  </code></pre>
  
  <p>where writely is the name of my website, and mrbk.writely@gmail.com is the account I wish to send an email from. </p>
  
  <p>Then in my Account Controller when I connect with my database and save the user in my table, I am creating my MailMessage object and attempting to same the mail by:</p>
  
  <pre><code>using (DBConnection conn = new DBConnection())
  {
         conn.UserInfoes.Add(userInfo);
         conn.SaveChanges();
  
         MailMessage mail = new MailMessage();
         mail.From = new MailAddress("mrbk.writely@gmail.com");
         mail.To.Add("bernice.zerafa11@gmail.com");
         mail.Subject = "Welcome to Writely";
         mail.Body = "Test content";
  
         SmtpClient smtp = new SmtpClient();
         smtp.Send(mail);
  }
  </code></pre>
  
  <p>Am I missing something or doing something wrong? I read that this is the good way to do this in some other question on stack overflow so I really don't know what's the problem here.</p>
  
  <p>Thanks for your help :)</p>