I need to send an email from my program I wrote this code but it did not work the error was
" Le serveur SMTP requiert une connexion sécurisée ou le client n'était pas authentifié. La réponse du serveur était : 5.7.0 Must issue a STARTTLS command first. e2sm19845644wix.15 - gsmtp "
English Translation:
"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 e2sm19845644wix.15 - gsmtp"
private void button3_Click(object sender, EventArgs e)
{
    try
    {   
         MailMessage mail = new MailMessage();
        SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
         SmtpServer.Credentials = new System.Net.NetworkCredential("oussabdalla@gmail.com", "xxx");
        mail.From = new MailAddress("oussabdalla@gmail.com");
        mail.To.Add(textBox4.Text);
        mail.Subject = "Attention";
        mail.Body = textBox1.Text + textBox2.Text + textBox3.Text + "est absent de " + comboBox5.SelectedValue + "a" + comboBox4.SelectedValue;
        SmtpServer.Port = 587;
        SmtpServer.Send(mail);
        SmtpServer.EnableSsl = true;
        MessageBox.Show("mail Send");
    }
    catch (Exception ex)  
    {
        MessageBox.Show(ex.ToString());
    }
}
I changed my code following recommendations and got a new error
" Le délai d'attente de l'opération a expiré "
Translated:
"The transaction timeout has expired"
private void button3_Click(object sender, EventArgs e)
{
        try
        {
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
            MailMessage mail = new MailMessage();
            SmtpServer.Credentials = new System.Net.NetworkCredential("oussabdalla@gmail.com", "xxxxx");
            SmtpServer.UseDefaultCredentials = false;
        mail.From = new MailAddress("oussabdalla@gmail.com");
        mail.To.Add(textBox4.Text);
        mail.Subject = "Attention";
        mail.Body = textBox1.Text + textBox2.Text + textBox3.Text + "est absent de " + comboBox5.SelectedValue + "a" + comboBox4.SelectedValue;
        SmtpServer.Port = 465;
        SmtpServer.EnableSsl = true;
        SmtpServer.Send(mail);
        MessageBox.Show("mail Send");
    }
    catch (Exception ex)  
    {
        MessageBox.Show(ex.ToString());
    }
}
 
     
     
     
    