title: MailMessage System.Net.Mail.SmtpException, Error when trying to send email via C# form
body: <p>hi im stuck and keep getting errors when trying to setup a send email for. </p>
  
  <p>here's my using.system:</p>
  
  <pre><code>using System.Net;
  using System.Web;
  using System.Net.Mail;
  </code></pre>
  
  <p>i then have this code in my send email button.</p>
  
  <pre><code>private void BtnEmail_Click(object sender, EventArgs e)
          {
  
  
              try
              {
                  string to = "myEmail@gmail.com";
                  string from = "myEmail@gmail.com";
                  string subject = "Test email";
                  string body = @"This is a test email";
  
  
                  MailMessage mail = new MailMessage(from, to, subject, body);
                  SmtpClient client = new SmtpClient("smtp.gmail.com");
                  client.Credentials = new NetworkCredential ("myEmail@gmail.com", "myPassword");
                  client.Port = 587;
                  client.EnableSsl = true;
                  client.Send(mail);
                  MessageBox.Show("Mail Sent", "Success", MessageBoxButtons.OK);
              }
              catch (Exception ex)
              {
                  MessageBox.Show(ex.Message + "\n\n" + ex.GetType().ToString() + "\n\n" + ex.StackTrace, "Exception");
              }
          }
  </code></pre>
  
  <p>it looks like the exception is being through at the "client.send(mail);" line.</p>
  
  <p>the catch exception message is: Failure sending mail.. System.Net.Mail.SmtpException.</p>
  
  <p>any idea whats going wrong here?? Thanks.</p>