Torna al Thread

static public bool SendMail(string mittente, string destinatario, string oggetto, string corpo) { bool res = true; corpo = Formattazione.PulisciDocumento(corpo); try { MailMessage msg = new MailMessage(); msg.From = new MailAddress(mittente, mittente); string[] destinatari = destinatario.Replace(",", ";").Split(char.Parse(";")); foreach (string to in destinatari) msg.To.Add(new MailAddress(to, to)); msg.Subject = oggetto; //********************* vedi funzione originale sotto, dovrebbe evitare antispam****** 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); msg.IsBodyHtml = true; //300316 msg.Priority = MailPriority.High; //300316 //************************************************************************************/ SmtpClient smtpClient = new SmtpClient(); smtpClient.Send(msg); } catch (SmtpException smtpException) { res = false; } catch (Exception ex) { res = false; } return res; } <system.net> <mailSettings> <smtp deliveryMethod="Network" from="noreply@xxx.com"> <network host="smtp.aruba.it" userName="noreply@xxx.com" password="xxx" port="25" /> </smtp> </mailSettings> </system.net>
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5