public static Exception Send(MessageSmtp messagesmtp, bool Trace = false) { Exception Result = null; SmtpClient client = (SmtpClient)_ServeurInfo; MailMessage message = (MailMessage)messagesmtp; if (Trace) { TraceFile.WriteLine("<----------"); TraceFile.WriteLine($" Subjet {message.Subject}"); TraceFile.WriteLine($" To {messagesmtp.To.Aggregate((a, b) => a + ";" + b)}"); } try { client.Send(message); } catch (Exception ex) { Result = new Exception($"Echec du message {message.Subject}", ex);; } #if NET45 client.Dispose(); #endif if (Trace) { TraceFile.WriteLine("---------->"); } return(Result); }
public static void BuildBody(this MessageSmtp Mess, string Message, string Service, string Signature) { HtmlElement html = new HtmlElement(); html.Child(new HtmlElement() { Txt = "<META CHARSET=\"UTF-8\" />" }); html.Child(new HtmlElement("font", new HtmlAttribute("size", "1"))); html.Child(new HtmlElement("style").Text("div.MsoMessage { font-size:12.0pt;font-family:\"Garamond\",\"serif\"; } span.MsoNormal, p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0cm; margin-bottom:.0001pt; font-size:12.0pt; font-family:\"Garamond\",\"serif\"; color:#0094ff; }")); var table = new HtmlElement("div"); table.Child(new HtmlElement("div", new HtmlAttribute("class", "MsoMessage")).Text(Message)); html.Child(table); table.Child( new HtmlElement("p", new HtmlAttribute("class", "MsoNormal")).Child( new HtmlElement("span", new HtmlAttribute("class", "MsoNormal")) .Text(Service))); table.Child( new HtmlElement("p", new HtmlAttribute("class", "MsoNormal")).Child( new HtmlElement("span", new HtmlAttribute("class", "MsoNormal")) .Text(Signature))); Mess.Body = html.ToString(); }
public static void SendMailAsync(MessageSmtp messagesmtp) { SmtpClient client = (SmtpClient)_ServeurInfo; client.SendCompleted += Client_SendCompleted; MailMessage message = (MailMessage)messagesmtp; client.SendMailAsync(message); }
public static void SendAsync(MessageSmtp messagesmtp) { Task.Factory.StartNew(() => Send(messagesmtp), TaskCreationOptions.LongRunning); }