title: SMTP "Failure sending mail" exception after deploy, works well with localhost
body: <p>Using the tutorial in this link <a href="https://www.codeproject.com/Tips/1081578/How-to-Implement-Contact-Us-Page-in-ASP-NET-MVC-AS" rel="nofollow noreferrer">How to Implement Contact Us Page in ASP.NET MVC (ASP.NET 5 )</a>. I managed to get my application send email to my gmail account. However, it is failing after publish and gives "Failure sending mail" error. I have done the possible fixes which you can see below but didn't help. Thank you.</p>
  
  <p>Here is my HomeController code:</p>
  
  <pre><code>public ActionResult Contact(Contact c)
      {
          if (ModelState.IsValid)
          {
              try
              {
                  MailMessage msg = new MailMessage();
                  StringBuilder sb = new StringBuilder();
                  msg.From = new MailAddress("example1@gmail.com");
                  msg.To.Add("example1@gmail.com");
                  msg.Subject = c.Subject;
                  //msg.IsBodyHtml = false;
                  sb.Append("&lt;b&gt;First name: &lt;/b&gt;" + c.FirstName + "&lt;br/&gt;&lt;br/&gt;");
                  sb.Append("&lt;b&gt;Last name: &lt;/b&gt;" + c.LastName + "&lt;br/&gt;&lt;br/&gt;");
                  sb.Append("&lt;b&gt;Email: &lt;/b&gt;" + c.Email + "&lt;br/&gt;&lt;br/&gt;");
                  sb.Append("&lt;b&gt;Phone: &lt;/b&gt;" + c.PhoneNumber + "&lt;br/&gt;&lt;br/&gt;");
                  sb.Append("&lt;b&gt;Message: &lt;/b&gt;" + c.Message + "&lt;br/&gt;&lt;br/&gt;");
                  msg.Body = sb.ToString();
                  msg.IsBodyHtml = true;
                  // We use gmail as our smtp client
                  SmtpClient smtpClient = new SmtpClient(); 
                  smtpClient.Send(msg);
                  msg.Dispose();
                  ModelState.Clear();
                  ViewBag.ContactMessage = "Your Message has been sent. Thank you for Contacting us. ";
              }
              catch (Exception ex)
              {
                  ModelState.Clear();
                  ViewBag.ContactMessage = $" Sorry we are facing the following Problem: {ex.Message}";
              }
          }
          return View();
      }
  </code></pre>
  
  <p>And my Web.config file:</p>
  
  <pre><code>&lt;system.net&gt;
      &lt;mailSettings&gt;
          &lt;smtp deliveryMethode="Network"&gt;
              &lt;network host="smtp.gmail.com" port"587" userName="***" password="***" enableSsl="true"/&gt;
          &lt;/smtp&gt;
      &lt;/mailSettings&gt;
  &lt;/system.net&gt;
  </code></pre>