public UtilityResult SendInternal(SmtpMessage message) { var rit = new UtilityResult(); if (string.IsNullOrEmpty(message.Body)) message.Body = ""; var bodyUpper = message.Body.ToUpper(); var mail = new MailMessage { From = new MailAddress(message.From), Subject = string.IsNullOrEmpty(message.Subject) ? "" : message.Subject.TruncateLongString(259), Body = message.Body, IsBodyHtml = bodyUpper.Contains("<HTML>") || bodyUpper.Contains("<BR") || bodyUpper.Contains("<A") }; // Eventualmente se ci siamo persi altri tag usare anche questo. // http://stackoverflow.com/questions/204646/how-to-validate-that-a-string-doesnt-contain-html-using-c-sharp // Regex tagRegex = new Regex(@"<\s*([^ >]+)[^>]*>.*?<\s*/\s*\1\s*>"); if (message.To != null && message.To.Any(el => !string.IsNullOrEmpty(el))) message.To.Where(el => !string.IsNullOrEmpty(el)).Each(el => mail.To.Add(new MailAddress(el))); if (message.Cc != null && message.Cc.Any(el => !string.IsNullOrEmpty(el))) message.Cc.Where(el => !string.IsNullOrEmpty(el)).Each(el => mail.CC.Add(new MailAddress(el))); if (message.Bcc != null && message.Bcc.Any(el => !string.IsNullOrEmpty(el))) message.Bcc.Where(el => !string.IsNullOrEmpty(el)).Each(el => mail.Bcc.Add(new MailAddress(el))); if (message.Attachments != null) message.Attachments.ToList().ForEach(el => mail.Attachments.Add(el)); var client = CreateSmtpClient(); client.Send(mail); return rit; }
public UtilityResult Send(SmtpMessage message) { var ret = SendInternal(message); return ret; }