1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
public static void Envois(MailMessage message) {
SmtpClient smtp = new SmtpClient();
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
try {
smtp.SendCompleted += new SendCompletedEventHandler(smtp_SendCompleted);
String etat = "Envoi message";
smtp.SendAsync(message, etat);
}
catch (SmtpException ex) {
throw new Exception("Erreur envois mail ! " + ex.StatusCode);
}
finally {
message.Dispose();
smtp = null;
}
}
private static void smtp_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) {
// Get the unique identifier for this asynchronous operation.
String token = (string)e.UserState;
if (e.Cancelled) {
ResultatEnvois = String.Format("[{0}] envois mail annuler.", token);
}
if (e.Error != null) {
ResultatEnvois = String.Format("[{0}] {1}", token, e.Error.ToString());
}
else {
ResultatEnvois = "Mail envoyé";
}
mailEnvois = true;
} |
Partager