private void DoWorkEmail(object EmailClass) { LogHelper.WriteLog("进入 DoWorkEmail 方法"); EmailInforMation emailInfo = (EmailInforMation)EmailClass; SendEmail(emailInfo, EmailType.Html); }
/// <summary> /// 邮件发送 /// </summary> /// <param name="listEmailAddress">收件人地址和内容</param> /// <param name="strTitle">邮件主题</param> /// <param name="mailName">邮件名称(考试、培训等)</param> public void SendEmail(List <KeyValuePair <string, string> > listEmailAndContent, string strTitle, string mailName = "") { try { EmailInforMation emailinf = new EmailInforMation(); emailinf.listEmailAndContent = listEmailAndContent; emailinf.SendFlag = 1; emailinf.Subject = strTitle; if (!string.IsNullOrEmpty(mailName)) { emailinf.mailName = mailName; } string[] emailStr = AllSystemConfigs.Where(p => p.ConfigType == 1).FirstOrDefault().ConfigValue.Split(';'); if (emailStr.Length > 0) { emailinf.UserName = emailStr[0]; emailinf.PassWord = emailStr[1]; //接收邮件服务器 emailinf.From = emailStr[2]; //发送邮件服务器 emailinf.Host = emailStr[4]; //端口 emailinf.IPort = Convert.ToInt32(emailStr[3]); } new RabbitMQHelper(Rabbit_serverAddress, Rabbit_userName, Rabbit_password, Rabbit_SendEmailHost, email_queue).SendMessage(emailinf); } catch { } }
private void DoWorkEmail(object EmailClass) { Console.WriteLine("进入 DoWorkEmail 方法"); EmailInforMation emailInfo = (EmailInforMation)EmailClass; SendEmail(emailInfo, EmailType.Html); }
public bool SendEmail(EmailInforMation infomation, EmailType type) { try { try { MailMessage message = new MailMessage(); //获取发送者地址 message.From = new MailAddress(infomation.UserName); //获取主题 message.Subject = infomation.Subject; //获取发送邮件主题 message.Body = infomation.Context; if (type == EmailType.Html) { message.IsBodyHtml = true; } else { message.IsBodyHtml = false; } foreach (string strEmailTo in infomation.ToList) { SmtpClient smtp = new SmtpClient(infomation.Host, infomation.IPort); smtp.Credentials = new NetworkCredential(infomation.UserName, infomation.PassWord); smtp.EnableSsl = false; // 如果使用GMail,则需要设置为true //执行查询获得要发往的邮件地址 try { message.To.Clear(); message.To.Add(strEmailTo); smtp.Send(message); } catch { return(false); } } return(true); } catch { return(false); } } catch { return(false); } }
public void testEmai() { LiXinBLL.Email em = new LiXinBLL.Email(); EmailInforMation model = new EmailInforMation(); model.Context = "啊啊啊"; //model.UserName = "******"; //model.PassWord = "******"; //model.From = "*****@*****.**"; //model.Host = "mail.retechcorp.com"; model.UserName = "******"; model.PassWord = "******"; model.From = "*****@*****.**"; model.Host = "smtp.qq.com"; List <string> a = new List <string>(); a.Add("*****@*****.**"); model.ToList = a; em.SendEmail(model, 0); }
public void SendEmail(EmailInforMation infomation, EmailType type) { try { try { log4net.Config.XmlConfigurator.Configure(); LogHelper.WriteLog("进入 SendEmail方法"); MailMessage message = new MailMessage(); //获取发送者地址 message.From = new MailAddress(infomation.UserName, infomation.FromUserName, Encoding.UTF8); //获取主题 message.Subject = infomation.Subject; if (type == EmailType.Html) { message.IsBodyHtml = true; } else { message.IsBodyHtml = false; } Console.WriteLine("循环 list开始发送邮件"); if (infomation.listEmailAndContent.Count > 0 && infomation.listEmailAndContent != null) { foreach (var strEmailTo in infomation.listEmailAndContent) { SmtpClient client = new SmtpClient(); client.UseDefaultCredentials = true; client.Credentials = new NetworkCredential(infomation.UserName, infomation.PassWord); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.Host = infomation.Host; // 如果使用GMail,则需要设置为true //如果是发送邮箱是gmail要加上这个代码否则邮件无法发送成功 if (client.Host == "smtp.gmail.com") { client.EnableSsl = true; client.Port = infomation.IPort; } //执行查询获得要发往的邮件地址 //获取发送邮件主题 message.Body = strEmailTo.Value; try { Thread.Sleep(10000); message.To.Clear(); message.To.Add(strEmailTo.Key); client.Send(message); LogHelper.WriteLog("收件人:" + message.To + ",发送成功"); } catch (Exception ex) { LogHelper.ErrorLog("循环 list异常:" + ex.Message); } } //LogHelper.WriteLog("发送成功"); } else { message.Body = infomation.Context; foreach (string strEmailTo in infomation.ToList) { SmtpClient client = new SmtpClient(); client.UseDefaultCredentials = true; client.Credentials = new NetworkCredential(infomation.UserName, infomation.PassWord); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.Host = infomation.Host; // 如果使用GMail,则需要设置为true //如果是发送邮箱是gmail要加上这个代码否则邮件无法发送成功 if (client.Host == "smtp.gmail.com") { client.EnableSsl = true; client.Port = infomation.IPort; } //执行查询获得要发往的邮件地址 try { Thread.Sleep(10000); message.To.Clear(); message.To.Add(strEmailTo); client.Send(message); LogHelper.WriteLog("收件人:" + message.To + ",发送成功"); } catch (Exception ex) { LogHelper.ErrorLog("单条异常:" + ex.Message); } } //LogHelper.WriteLog("---------------End------------------"); } } catch (Exception ex) { LogHelper.ErrorLog(ex.Message); } } catch (Exception ex) { LogHelper.ErrorLog(ex.Message); } }
/// <summary> /// 群发邮件的方法 /// </summary> /// <param name="emailInfo">邮件的基础信息</param> public void SendAllEmail(EmailInforMation emailInfo) { Thread t = new Thread(new ParameterizedThreadStart(DoWorkEmail)); t.Start(emailInfo); }
private void DoWorkEmail(object EmailClass) { EmailInforMation emailInfo = (EmailInforMation)EmailClass; SendEmail(emailInfo, EmailType.Html); }
public void SendEmail(EmailInforMation infomation, EmailType type) { try { try { log4net.Config.XmlConfigurator.Configure(); LogHelper.WriteLog("---------------Begin:" + DateTime.Now + "------------------"); LogHelper.WriteLog("进入 SendEmail方法"); MailMessage message = new MailMessage(); //获取发送者地址 message.From = new MailAddress(infomation.UserName); //获取主题 message.Subject = infomation.Subject; if (type == EmailType.Html) { message.IsBodyHtml = true; } else { message.IsBodyHtml = false; } LogHelper.WriteLog("循环 list开始发送邮件"); if (infomation.listEmailAndContent.Count > 0 && infomation.listEmailAndContent != null) { foreach (var strEmailTo in infomation.listEmailAndContent) { SmtpClient smtp = new SmtpClient(infomation.Host, infomation.IPort); smtp.Credentials = new NetworkCredential(infomation.UserName, infomation.PassWord); smtp.EnableSsl = false; // 如果使用GMail,则需要设置为true //执行查询获得要发往的邮件地址 //获取发送邮件主题 message.Body = strEmailTo.Value; try { message.To.Clear(); message.To.Add(strEmailTo.Key); smtp.Send(message); LogHelper.ErrorLog("发送"); LogHelper.WriteLog("收件人:" + message.To + ",内容:" + message.Body + ",发送成功"); } catch (Exception ex) { LogHelper.ErrorLog("循环 list异常:" + ex.Message); } } //LogHelper.WriteLog("发送成功"); } else { message.Body = infomation.Context; foreach (string strEmailTo in infomation.ToList) { SmtpClient smtp = new SmtpClient(infomation.Host, infomation.IPort); smtp.Credentials = new NetworkCredential(infomation.UserName, infomation.PassWord); smtp.EnableSsl = false; // 如果使用GMail,则需要设置为true //执行查询获得要发往的邮件地址 try { message.To.Clear(); message.To.Add(strEmailTo); smtp.Send(message); LogHelper.WriteLog("收件人:" + message.To + ",内容:" + message.Body + ",发送成功"); } catch (Exception ex) { LogHelper.ErrorLog("单条异常:" + ex.Message); } } //LogHelper.WriteLog("---------------End------------------"); } } catch (Exception ex) { LogHelper.ErrorLog(ex.Message); } } catch (Exception ex) { LogHelper.ErrorLog(ex.Message); } }