envoi email en c# code example
Example: envoi email en c#
private void button1_Click(object sender, EventArgs e)
{
MailMessage email = new MailMessage();
email.From = new System.Net.Mail.MailAddress("[email protected]");
email.To.Add(new MailAddress("[email protected]"));
email.IsBodyHtml = true;
email.Subject = "objet du mail";
email.Body = " contenu du mail";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new System.Net.NetworkCredential("source", "mot-de-passe");
try
{
smtp.Send(email);
MessageBox.Show("email est envoyer");
}
catch (SmtpException ex)
{
MessageBox.Show(ex.Message);
}
}