public async Task <IActionResult> SendEmail(int logId) { SendEmailLogBll sendEmailLogBll = new SendEmailLogBll(); var log = await sendEmailLogBll.GetById(logId); SendEmailHelper.SendEmail(log); return(Json(new { code = 1, msg = "OK" })); }
public async Task <IActionResult> OpenEmailCallBack(int logid) { SendEmailLogBll bll = new SendEmailLogBll(); var info = await bll.GetById(logid); if (info != null) { info.IsRead = true; } bll.Update(info); return(Json(new { code = 1, msg = "OK" })); }
/// <summary> /// 邮件发送日志 /// </summary> /// <param name="sendEmailTaskId"></param> /// <param name="pageIndex"></param> /// <returns></returns> public IActionResult SendEmailLogList(int sendEmailTaskId, int pageIndex = 1) { SendEmailLogBll sendEmailLogBll = new SendEmailLogBll(); int pageSize = 35; var tup = sendEmailLogBll.GetByTaskId(sendEmailTaskId, pageIndex, pageSize); SendEmailTaskBll sendEmailTaskBll = new SendEmailTaskBll(); var taskinfo = sendEmailTaskBll.GetById(sendEmailTaskId).Result; ViewBag.pageIndex = pageIndex; ViewBag.pageSize = pageSize; ViewBag.count = tup.Item2; ViewBag.sendEmailTaskId = sendEmailTaskId; ViewBag.taskinfo = taskinfo; ViewBag.root = "email"; return(View(tup.Item1)); }
public static void SendEmail(SendEmailLog log) { try { EmailResourcesBll emailResourcesBll = new EmailResourcesBll(); List <EmailResources> emailResourceses = emailResourcesBll.GetLists(); EmailTemplateBll emailTemplateBll = new EmailTemplateBll(); SendEmailLogBll sendEmailLogBll = new SendEmailLogBll(); if (emailResourceses == null || emailResourceses.Count == 0) { return; } Random r = new Random(); int i = r.Next(0, emailResourceses.Count - 1); var emailResourcese = emailResourceses[i]; var template = emailTemplateBll.GetByIds(log.EmailTempId); string url = $"http://open.lsc.com:8080/Account/OpenEmailCallBack?logid=" + log.Id; string imag = $"<img src=\"{url}\" style=\"width: 1px; height: 1px;\" />"; string emailCount = template.EmailContent + "<br/>" + imag;//邮箱内容 EmailHelper emailHelper = new EmailHelper(emailResourcese.SenderServerIp, log.Email, emailResourcese.Email, template.Title, emailCount, emailResourcese.UserName, emailResourcese.Password, emailResourcese.Port, false, false); try { emailHelper.Send(); log.IsSendOk = true; } catch (Exception e) { log.IsSendOk = false; } log.IsSend = true; sendEmailLogBll.Update(log); } catch (Exception e) { } }
/// <summary> /// 开始发送 /// </summary> public static void StartSendEmail(int sendEmailTaskId) { if (sendEmailTaskId <= 0) { ClassLoger.Fail("SendEmailHelper.StartSendEmail", "邮件发送任务Id小于0不能发送任务"); return; } Task.Run(() => { ClassLoger.Info("SendEmailHelper.StartSendEmail", "开始发送邮件"); SendEmailLogBll sendEmailLogBll = new SendEmailLogBll(); EmailTemplateBll emailTemplateBll = new EmailTemplateBll(); try { EmailResourcesBll emailResourcesBll = new EmailResourcesBll(); List <EmailResources> emailResourceses = emailResourcesBll.GetLists(); if (emailResourceses == null || emailResourceses.Count == 0) { ClassLoger.Fail("SendEmailHelper.StartSendEmail", "邮件资源为空不能发邮件"); } int pageIndex = 0; int pageSize = 60; A: pageIndex++; var tup = sendEmailLogBll.GetNoSendByTaskId(sendEmailTaskId, pageIndex, pageSize); if (tup.Item1 != null && tup.Item1.Count > 0) { foreach (var sendEmailLog in tup.Item1) { Random r = new Random(); int i = r.Next(0, emailResourceses.Count - 1); var emailResourcese = emailResourceses[i]; var template = emailTemplateBll.GetByIds(sendEmailLog.EmailTempId); string url = $"http://open.lsc.com:8080/Account/OpenEmailCallBack?logid=" + sendEmailLog.Id; string imag = $"<img src=\"{url}\" style=\"width: 1px; height: 1px;\" />"; string emailCount = template.EmailContent + "<br/>" + imag;//邮箱内容 EmailHelper emailHelper = new EmailHelper(emailResourcese.SenderServerIp, sendEmailLog.Email, emailResourcese.Email, template.Title, emailCount, emailResourcese.UserName, emailResourcese.Password, emailResourcese.Port, false, false); try { emailHelper.Send(); sendEmailLog.IsSendOk = true; } catch (Exception e) { sendEmailLog.IsSendOk = false; } sendEmailLog.IsSend = true; sendEmailLogBll.Update(sendEmailLog); Thread.Sleep(1000 * 60 * 3); } goto A; } } catch (Exception e) { ClassLoger.Error("SendEmailHelper.SendEmail", e); } }); }
public async Task <IActionResult> SaveSendEmailTask() { SendEmailTask sendEmailTask = new SendEmailTask(); SendEmailLogBll sendEmailLogBll = new SendEmailLogBll(); sendEmailTask.EmailTempId = Request.Form["EmailTempId"].TryToInt(0); sendEmailTask.TaskName = Request.Form["TaskName"].TryToString(); sendEmailTask.CreateTime = DateTime.Now; string Email = Request.Form["Email"].TryToString(); bool flag = Request.Form["sendAll"].TryToString() == "on"; SendEmailTaskBll bll = new SendEmailTaskBll(); int id = await bll.AddAsync(sendEmailTask); if (id > 0) { Task.Run(async() => { if (!Email.IsNull()) { SendEmailLog log = new SendEmailLog { SendEmailTaskId = id, Email = Email, IsRead = false, IsSend = false, IsSendOk = false, Name = Email, EmailTempId = sendEmailTask.EmailTempId, }; await sendEmailLogBll.AddAsync(log); } if (flag) { TargetEmailBll targetEmailBll = new TargetEmailBll(); int pageIndex = 0; int pageSize = 50; A: pageIndex++; var tup = await targetEmailBll.GetList(pageIndex, pageSize); if (tup.Item1 != null && tup.Item1.Count > 0) { foreach (TargetEmail targetEmail in tup.Item1) { SendEmailLog log1 = new SendEmailLog { SendEmailTaskId = id, Email = targetEmail.Email, IsRead = false, IsSend = false, IsSendOk = false, Name = targetEmail.Name, EmailTempId = sendEmailTask.EmailTempId, }; await sendEmailLogBll.AddAsync(log1); } goto A; } } SendEmailHelper.StartSendEmail(id); }); } return(Json(new { code = 1, msg = "OK" })); }