title: System.Net.Mail.SmtpException - Email Sender
body: <p>Net.Mail.SmtpException in output when I send any message using Email Sender application made in C#. </p>
  
  <p><strong>ERROR:</strong> <strong>System.Net.Mail.Smtp.Exception: 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 System.Net.MailCommand.CheckResponse(SmtpStatusCodestatusCde,Stringresponse)
  at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddressfrom,Boolean allowUnicode) at System.Net.Mail.Smtp.Transport.SendMail(MailAddress sender,MailAddressCollection recipients, String deliveryNotify,Boolean allowUnicode, SmtpFailedRecipientException&amp; exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at My_first_project.Form1.button2_Click(Object sender, EventArgs e) in c:\Users\HUSSAM\Documents\Visual Studio 2012\Projects\C#\Projects\My first project\My first project\Form1.cs:line 80</strong></p>
  
  <p>Here is the CODE::</p>
  
  <pre><code>private void button2_Click(object sender, EventArgs e){
  
          try
          {
              if (!textBox4.Text.Contains("@gmail.com"))
              {
  
                  MessageBox.Show("You need to provide @gmail email :)");
                  return;
  
              }
  
              button2.Enabled = false;
              MailMessage message = new MailMessage();
              message.From = new MailAddress(textBox4.Text);
              message.Subject = textBox2.Text;
              message.Body = textBox3.Text;
  
              foreach (string s in textBox1.Text.Split(';'))
                  message.To.Add(s);
  
              SmtpClient client = new SmtpClient();
              client.UseDefaultCredentials = false;
              client.Credentials = new NetworkCredential(textBox4.Text, textBox5.Text);
              client.Host = "smtp.gmail.com";
              client.Port = 587;
              client.DeliveryMethod = SmtpDeliveryMethod.Network;
              client.EnableSsl = true;
              client.Send(message);
  
          }//end try
          catch
          {
  
              MessageBox.Show("There was error sending the message. Make sure you typed in\r\nyour credentials correctly and that you have an internet connection.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
  
          }
          finally { button2.Enabled = true; }
      }//end button function
  </code></pre>