title: Cannot send email in ASP.NET MVC
body: <p>I would like to send email in ASP.NET MVC and here my code:</p>
  
  <pre><code>public ActionResult Index(MyMailModel objMailModel)
      {
          if (ModelState.IsValid)
          {
              string from = "******@gmail.com";
              using (MailMessage mail = new MailMessage(from, objMailModel.To))
              {
                  mail.Subject = "Backup Database";
                  mail.Body = "hahaha";
                  mail.IsBodyHtml = false;
                  SmtpClient smtp = new SmtpClient();
                  smtp.Host = "smtp.gmail.com";
                  smtp.EnableSsl = true;
                  NetworkCredential network = new NetworkCredential(from, "*******");                    
                  smtp.UseDefaultCredentials = true;
                  smtp.Credentials = network;
                  smtp.Port = 587;
                  smtp.Send(mail);
                  ViewBag.Message = "Sent";
                  return View("Index", objMailModel);
              }
          }
          else
          {
              return View();
          }
  
      }
  </code></pre>
  
  <p>But, I have a error:</p>
  
  <p><strong>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 ******</strong>:587**</p>
  
  <p>Please help me.</p>
  
  <p>Thanks.</p>