Torna al Thread

static public bool SendNewsLetter(..., List<tipoAllegato> allegati) { bool res = true; MailMessage msg = new MailMessage(); ... msg.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8"); System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString (System.Text.RegularExpressions.Regex.Replace(corpo, @"<(.|\n)*?>", string.Empty), null, "text/plain"); System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(corpo, null, "text/html"); msg.AlternateViews.Add(plainView); msg.AlternateViews.Add(htmlView); //************************************************************************************/ foreach (tipoAllegato allegato in allegati) if (allegato.File != null && allegato.File.Trim() != string.Empty) msg.Attachments.Add(new Attachment(allegato.Allegato, allegato.File)); SmtpClient smtpClient = new SmtpClient(Costanti.SMTP_SERVER); try { smtpClient.Send(msg); } catch (SmtpException smtpException) { res = false; } catch (Exception ex) { res = false; } } return res; }
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5