title: sending email using gmail from asp.net
body: <p>I am trying to send mail using gmail in asp.net </p>
  
  <p>My Code:</p>
  
  <pre><code>using (MailMessage mm = new MailMessage(txtEmail.Text, txtTo.Text))
          {
              mm.Subject = txtSubject.Text;
              mm.Body = txtBody.Text;
              if (fuAttachment.HasFile)
              {
                  string FileName = Path.GetFileName(fuAttachment.PostedFile.FileName);
                  mm.Attachments.Add(new Attachment(fuAttachment.PostedFile.InputStream, FileName));
              }
              mm.IsBodyHtml = false;
              SmtpClient smtp = new SmtpClient();
              smtp.Host = "smtp.gmail.com";
              smtp.EnableSsl = true;
              smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
              NetworkCredential NetworkCred = new NetworkCredential(txtEmail.Text, txtPassword.Text);
              smtp.UseDefaultCredentials = true;
              smtp.Credentials = NetworkCred;
              smtp.Port = 587;
              smtp.Send(mm);
              ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
          }
  </code></pre>
  
  <p>But i am getting error:</p>
  
  <pre><code>The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
  </code></pre>
  
  <p>where is my error?</p>