title: How to send email from Asp.net Mvc-3?
body: <p>How to send a mail through mvc-3 asp.net using c#?</p>
  
  <p>I have to send a forgot password so how can I do this?
  My code is below.</p>
  
  <p>Model code..</p>
  
  <pre><code> using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.ComponentModel.DataAnnotations;
  
  namespace TelerikLogin.Models.ViewModels
  {
      public class ForgotPassword
      {
          public int user_id { get; set; }
          public string user_login_name { get; set; }
          public string user_password { get; set; }
  
          [Required]
          [Display(Name="Email Address : ")]
          public string user_email_address { get; set; }
      }
  }
  </code></pre>
  
  <p>Controller code..</p>
  
  <pre><code>  public ActionResult ForgotPassword()
          {
              return View();
          }
  
          [HttpPost]
          public ActionResult ForgotPassword(string user_email_address)
          {
              SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\MVC3\TelerikLogin\TelerikLogin\App_Data\Login.mdf;Integrated Security=True;User Instance=True");
  
              DataTable dt1 = new DataTable();
  
              string strQuery = string.Format("SELECT user_password FROM [user_master] WHERE user_email_address='{0}'",user_email_address);
              conn.Open();
              SqlDataAdapter da1 = new SqlDataAdapter(strQuery, conn);
              da1.Fill(dt1);
              conn.Close();
  
              if (dt1.Rows.Count &gt; 0)
              {
  
  MailMessage msg = new MailMessage();
  
              msg.From = new MailAddress("abc@gmail.com");
              msg.To.Add(user_email_address);
              msg.Subject = "Password";
              msg.Body = "Test1";
              msg.Priority = MailPriority.High;
  
              SmtpClient client = new SmtpClient();
  
  
  
  
              client.Credentials = new NetworkCredential("abc@gmail.com", "dip", "smtp.gmail.com");
              client.Host = "smtp.gmail.com";
              client.Port = 587;
              client.DeliveryMethod = SmtpDeliveryMethod.Network;
              client.EnableSsl = true;
              client.UseDefaultCredentials = true;
  
              client.Send(msg);
  
  
                 return RedirectToAction("About", "Home");
              }
              return View();
          }
  </code></pre>
  
  <p>Here I fetched the password of user from database through entered email address..</p>
  
  <p>View code..</p>
  
  <pre><code>&lt;% using (Html.BeginForm("ForgotPassword", "Account", FormMethod.Post))
     { %&gt;
  
     &lt;%: Html.LabelFor(m =&gt; m.user_email_address) %&gt;
     &lt;%: Html.TextBox("user_email_address")%&gt;
        &lt;%: Html.ValidationSummary(true) %&gt;
  
  &lt;input type="submit" value="Submit"/&gt;
  
     &lt;%} %&gt;
  </code></pre>
  
  <p>It gives me an error on these line</p>
  
  <pre><code> client.Send(msg);
  </code></pre>
  
  <p>Error messege is: </p>
  
  <pre><code>The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. x1sm1264662igc.16
  </code></pre>
  
  <p>How to solve it?
  thanks in advance</p>