public MailWrapper(XmlNode section, MailSendType type) { m_MailSendType = type; m_Mail = Create(type); int tmp; m_Config = m_Mail.AnalyseConfig(section, out tmp); m_RecoverSeconds = tmp; m_ErrorTimeList = new DateTime[m_Config.Count]; m_ErrorInfoList = new string[m_Config.Count]; for (int i = 0; i < m_Config.Count; i++) { m_ErrorTimeList[i] = DateTime.MinValue; } m_StartIndex = 0; }
private IMailSender Create(MailSendType type) { switch (type) { case MailSendType.Queue: return(new QueueMailSender()); case MailSendType.RestfulService: return(new RestfulMailSender()); case MailSendType.SoapService: return(new SoapMailSender()); default: // MailSendType.Smtp return(new SmtpMailSender()); } }
public static void Send(MailEntity entity, MailSendType type = MailSendType.Smtp) { MailWrapper wrapper; if (!s_Cache.TryGetValue(type, out wrapper)) { lock (s_SyncObj) { if (!s_Cache.TryGetValue(type, out wrapper)) { XmlNode section = ConfigurationManager.GetSection("mail") as XmlNode; wrapper = new MailWrapper(section, type); s_Cache.Add(type, wrapper); } } } wrapper.Send(entity); }
public static void Send(string fromAddress, string fromDisplay, List<string> toAddressList, List<string> ccAddressList, List<string> bccAddressList, string subject, string body, Encoding charset, bool isBodyHtml = true, MailPriority priority = MailPriority.Normal, MailSendType type = MailSendType.Smtp) { MailEntity entity = new MailEntity { FromAddress = fromAddress, FromDisplay = fromDisplay, ToAddressList = toAddressList, CcAddressList = ccAddressList, BccAddressList = bccAddressList, Subject =subject, Body = body, Charset = charset, IsBodyHtml = isBodyHtml, Priority = priority }; Send(entity, type); }
public static void Send(string fromAddress, string fromDisplay, List <string> toAddressList, List <string> ccAddressList, List <string> bccAddressList, string subject, string body, Encoding charset, bool isBodyHtml = true, MailPriority priority = MailPriority.Normal, MailSendType type = MailSendType.Smtp) { MailEntity entity = new MailEntity { FromAddress = fromAddress, FromDisplay = fromDisplay, ToAddressList = toAddressList, CcAddressList = ccAddressList, BccAddressList = bccAddressList, Subject = subject, Body = body, Charset = charset, IsBodyHtml = isBodyHtml, Priority = priority }; Send(entity, type); }
//Send Email with password public bool SendMailWithOutlook(string subject, string htmlBody, string recipients, MailSendType sendType) { // create the outlook application. Outlook.Application outlookApp = new Outlook.Application(); if (outlookApp == null) { return(false); } // create a new mail item. Outlook.MailItem mail = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem); // set html body. // add the body of the email mail.HTMLBody = htmlBody; mail.Subject = subject; mail.To = recipients; if (sendType == MailSendType.SendDirect) { mail.Send(); } else if (sendType == MailSendType.ShowModal) { mail.Display(true); } else if (sendType == MailSendType.ShowModeless) { mail.Display(false); } mail = null; outlookApp = null; return(true); }
private IMailSender Create(MailSendType type) { switch (type) { case MailSendType.Queue: return new QueueMailSender(); case MailSendType.RestfulService: return new RestfulMailSender(); case MailSendType.SoapService: return new SoapMailSender(); default: // MailSendType.Smtp return new SmtpMailSender(); } }
public static void Send(string fromAddress, string fromDisplay, string toAddress, string subject, string body, Encoding charset, bool isBodyHtml = true, MailPriority priority = MailPriority.Normal, MailSendType type = MailSendType.Smtp) { Send(fromAddress, fromDisplay, new List <string> { toAddress }, null, null, subject, body, charset, isBodyHtml, priority, type); }
public static void Send(string fromAddress, string fromDisplay, string toAddress, string subject, string body, bool isBodyHtml = true, MailPriority priority = MailPriority.Normal, MailSendType type = MailSendType.Smtp) { Send(fromAddress, fromDisplay, toAddress, subject, body, Encoding.UTF8, isBodyHtml, priority, type); }
public static void Send(string fromAddress, string fromDisplay, string toAddress, string subject, string body, Encoding charset, bool isBodyHtml = true, MailPriority priority = MailPriority.Normal, MailSendType type = MailSendType.Smtp) { Send(fromAddress, fromDisplay, new List<string> { toAddress }, null, null, subject, body, charset, isBodyHtml, priority, type); }
public bool SendMailWithOutlook(string subject, string htmlBody, string recipients, MailSendType sendType) { try { // create the outlook application. Outlook.Application outlookApp = new Outlook.Application(); if (outlookApp == null) { return(false); } // create a new mail item. Outlook.MailItem mail = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem); // set html body. // add the body of the email mail.HTMLBody = htmlBody; mail.Subject = subject; mail.To = recipients; if (sendType == MailSendType.SendDirect) { mail.Send(); } else if (sendType == MailSendType.ShowModal) { mail.Display(true); } else if (sendType == MailSendType.ShowModeless) { mail.Display(false); } mail = null; outlookApp = null; return(true); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return(false); } finally { MessageBox.Show("An Email has been sent to your account, check your inbox", "Email Sent Successfully!"); } }