using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Configuration; using System.Collections; using System.Xml; using System.Text; using System.IO; using System.Net.Mail; namespace AIAHTML5.API.Utility { public class EmailUtility { public string sFromAddress { get; set; } public List sToAddresses { get; set; } public List sBccAddresses { get; set; } public string sHostName { get; set; } public string sSubject { get; set; } public int iPort { get; set; } public bool bEnableSsl { get; set; } public string sUserName { get; set; } public string sPassword { get; set; } public bool bIsBodyHtml { get; set; } public List sAttachments { get; set; } public string sBodyText { get; set; } public AlternateView sAlternateView { get; set; } public void SendMail(MailMessage mm) { SmtpClient smtp = new SmtpClient(); smtp.Host = ConfigurationManager.AppSettings["SMTPAddress"]; smtp.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSSL"]); System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential(mm.From.ToString(), ConfigurationManager.AppSettings["SenderPassword"]); smtp.Credentials = NetworkCred; smtp.Port = Convert.ToInt32(ConfigurationManager.AppSettings["SMTPPort"]); /*string ccAddress = ConfigurationManager.AppSettings["NotifyCopyAddress"]; string[] emailArr = ccAddress.Split(','); if (mm.From.ToString().Equals("pfizerhelp@ebix.com")) { ccAddress = emailArr[0]; if (!ccAddress.Equals("")) { mm.Bcc.Add(ccAddress); } } else { if (!ccAddress.Equals("")) { mm.Bcc.Add(ccAddress); } }*/ smtp.Send(mm); } public void SendSmtpEmail() { try { MailMessage sMail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient(sHostName); string recipientEmailAddress = string.Empty; if (sToAddresses != null) { foreach (var sItem in sToAddresses) { sMail.To.Add(sItem); } } if (sBccAddresses != null) { foreach (var sItem in sBccAddresses) { sMail.Bcc.Add(sItem); } } sMail.IsBodyHtml = bIsBodyHtml; if (sAlternateView != null) { sMail.AlternateViews.Add(sAlternateView); } else { sMail.Body = sBodyText; } sMail.Subject = sSubject; if (sAttachments != null) { foreach (var sItem in sAttachments) { sMail.Attachments.Add(sItem); } } SmtpServer.Port = iPort; SmtpServer.Credentials = new System.Net.NetworkCredential(sUserName, sPassword); SmtpServer.EnableSsl = bEnableSsl; // SmtpServer.Send(sMail); using (MailMessage mm = new MailMessage(sFromAddress, sMail.To.ToString())) //using (MailMessage mm = new MailMessage()) { mm.Subject = sSubject; mm.IsBodyHtml = bIsBodyHtml; // mm.To.Add(sMail.To.ToString()); //mm.From = new MailAddress(sFromAddress, "AdamOnDemand"); if (sAlternateView != null) { mm.AlternateViews.Add(sAlternateView); } else { mm.Body = sBodyText; } // mm.Body = sAlternateView; // string bccAddress = (!string.IsNullOrEmpty(sBccAddresses) ? lstBccAddress : ConfigurationManager.AppSettings["AccountsEmailAddress"]); /* if (sBccAddresses != null) { foreach (var sItem in sBccAddresses) { mm.Bcc.Add(sItem); } }*/ //else //{ // string bccAddress = ConfigurationManager.AppSettings["AccountsEmailAddress"]; // mm.Bcc.Add(bccAddress); //} mm.IsBodyHtml = true; SendMail(mm); } } catch (Exception ex) { throw ex; } } } }