title: How to create an SMTP mail?
body: <p>I tried to send mail from my asp.net web application.</p>
  
  <p>I want to send my application password to the user mail id, for that I took the password from datatabase using <code>getdetailss</code> function.<br>
  <code>btn4getPwd</code> is the button calling the mailing function.<br>
  <code>txtusername.Text</code> is the text box containing sending mail address. All values are receiving correctly, no error occur but it's not working ..!</p>
  
  <pre><code>protected void btn4getPwd_Click(object sender, EventArgs e)
  {
      if (txtusername.Text.Trim() != "")
      {
          em.username = txtusername.Text.Trim();
          DataTable forget = em.getdetailss(10);
          string passwd = (forget.Rows[0]["PassCode"].ToString());
  
  
          try
          {
              string Subject = "Your NLS Password";
              string Body = passwd;
              string ToEmail = txtusername.Text.Trim();
              string SMTPUser = "mymail@gmail.com", SMTPPassword = "pswd";
  
              MailMessage mail = new MailMessage();
              mail.From = new MailAddress(SMTPUser, "AspnetO");
              mail.To.Add(ToEmail);
              mail.Body = Body;
              mail.IsBodyHtml = true;
              mail.Priority = MailPriority.Normal;
              SmtpClient smtp = new SmtpClient();
              smtp.Host = "smtp.gmail.com";
              smtp.Port = 25; 
              smtp.Credentials = new System.Net.NetworkCredential(SMTPUser, SMTPPassword);
              smtp.EnableSsl = true;
              smtp.Send(mail);
              Response.Write("&lt;script language=javascript&gt;alert('Mail send...!! ')&lt;/script&gt;");
          }
  
          catch (SmtpException ex)
          {
              lbl4get.Text = "SmtpException ";
          }
          catch (Exception ex)
          {
              lbl4get.Text = "Exception";
          }
      }
      else { Response.Write("&lt;script language=javascript&gt;alert('Invalid USERNAME...!! ')&lt;/script&gt;"); }
  
  }  
  </code></pre>