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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
/// <summary>
/// Description résumée de SendMailAuto.
/// </summary>
public class ServiceMailAuto : MailMessage
{
//Constructeur
public ServiceMailAuto()
{
}
/// <summary>
/// Obtient si le mail peux etre envoyé
/// </summary>
public bool canSend
{
get
{
object o = ConfigurationSettings.AppSettings["canSend"];
return (o==null?false:bool.Parse(o.ToString()));
}
}
/// <summary>
/// Send()
/// </summary>
public bool Send()
{
bool flag = true;
SmtpMail.SmtpServer = ConfigurationSettings.AppSettings["EmailServer"];
//si le serveur est en maintenance
if (!canSend)
return false;
try
{
SmtpMail.Send(this);
}
catch (Exception ex)
{
flag = false;
StreamWriter sw = new StreamWriter(ConfigurationSettings.AppSettings["Mail.log"],true);
sw.WriteLine(DateTime.Now + " " + this.Subject + " " + flag + " " + ex.Message);
sw.Close();
}
finally
{
this.Attachments.Clear();
this.Body = "";
this.Bcc = "";
this.Cc = "";
this.From = "";
this.Subject = "";
this.To = "";
}
return flag;
}
/// <summary>
/// Mail generic avec retour d envoi
/// </summary>
/// <param name="To">To</param>
/// <param name="From">From</param>
/// <param name="Subject">Sujet</param>
/// <param name="Body">Corps</param>
/// <returns>est envoye ?</returns>
public bool MailGeneric(string To, string From, string Subject, string Body)
{
BodyFormat = MailFormat.Html;
this.From = From;
this.To = To;
this.Subject = Subject;
this.Body = Body;
return Send();
}
/// <summary>
/// mail d'erreur sur écriture fichier
/// </summary>
public bool MailErreur(string ErrorMessage)
{
BodyFormat = MailFormat.Html;
From = ConfigurationSettings.AppSettings["DoNotReplyEmail"];
To = ConfigurationSettings.AppSettings["TechAdmin"];
Subject = "Erreur ecriture fichier Saolog batch";
Body = "<div style='font-family: Verdana; font-size: 12px'>";
Body += "Erreur ecriture fichier Saolog batch";
Body += ErrorMessage;
return Send();
}
} |
Partager