public async Task AddSendEmailLog(string message, string fromEmail, string toEmail, string recipientUserId) { try { using (var context = new ApiMohoContext()) { var log = new SendEmailLog() { Message = message, FromEmail = fromEmail, RecipientUserId = recipientUserId, ToEmail = toEmail }; await context.AddAsync(log); await context.SaveChangesAsync(); } } catch (Exception e) { Console.WriteLine(e); throw; } }
public int Update(SendEmailLog senbEmailLog) { int id = 0; try { DataContext dataContext = new DataContext(); var entity = dataContext.SendEmailLogs.Update(senbEmailLog); dataContext.SaveChanges(); id = entity.Entity.Id; } catch (Exception e) { ClassLoger.Error("SendEmailLogDal.Update", e); } return(id); }
public SendEmailLogDto CreateDtoFromEntity(SendEmailLog entity) { var dto = new SendEmailLogDto(); dto.OrganizationUid = entity.OrganizationUid; dto.OrganizationName = entity.OrganizationName; dto.MailUid = entity.MailUid; dto.Subject = entity.Subject; dto.EmailFrom = entity.EmailFrom; dto.EmailTo = entity.EmailTo; dto.IsOpened = entity.IsOpened; return(dto); }
public static SendEmailLog GetSendEmailLog() { var sendEmailLog = new SendEmailLog(); sendEmailLog.OrganizationId = LongOne; sendEmailLog.OrganizationUid = UidOne; sendEmailLog.OrganizationName = StringOne; sendEmailLog.Id = LongOne; sendEmailLog.Uid = UidOne; sendEmailLog.Name = StringOne; sendEmailLog.CreatedAt = DateTimeOne; sendEmailLog.EmailFrom = StringOne; sendEmailLog.EmailTo = StringOne; sendEmailLog.Subject = StringOne; return(sendEmailLog); }
public async Task <int> AddAsync(SendEmailLog senbEmailLog) { int id = 0; try { DataContext dataContext = new DataContext(); var entity = await dataContext.SendEmailLogs.AddAsync(senbEmailLog); await dataContext.SaveChangesAsync(); id = entity.Entity.Id; } catch (Exception e) { ClassLoger.Error("SendEmailLogDal.AddAsync", e); } return(id); }
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) { } }
//发送邮件 外部提交-根据固定的模板发送邮件 private void sendEmail(string taskID, string templateID, int eid, string custID) { //url string urlHead = ConfigurationUtil.GetAppSettingValue("TaskProcessUrl"); //找到邮件接收人的邮箱 string userEmail = BLL.Util.GetEmployeeEmailByEid(eid); //1 插入 发送邮件日志表 (记录) SendEmailLog model_Email = new SendEmailLog(); string templateName = BLL.Util.GetEmployeeNameByEid(eid);//收件人姓名 string urlInternal = urlHead + "/TaskManager/TaskProcess.aspx?TaskID=" + taskID; string urlExternal = urlHead + "/ExternalTask/ExternalTaskProcess.aspx?TaskID=" + taskID; string templateTitle = string.Empty; //模板标题 string templateLog = string.Empty; //模板日志 string templateUrl = string.Empty; //模板链接格式 int _templateID; //模板ID //根据TaskID和受理人ID获取所要发送的模板ID if (int.TryParse(templateID, out _templateID)) { QueryCustHistoryTemplateMapping query_Template = new QueryCustHistoryTemplateMapping(); query_Template.TaskID = taskID; query_Template.SolveUserEID = eid; int count; DataTable dt_Template = BLL.CustHistoryTemplateMapping.Instance.GetCustHistoryTemplateMapping(query_Template, "", 1, 10000, out count); if (dt_Template != null) { //根据模板ID获取模板内容 TemplateInfo model_TemplateInfo = new TemplateInfo(); model_TemplateInfo = BLL.TemplateInfo.Instance.GetTemplateInfo(_templateID); if (model_TemplateInfo == null) { return; } //templateInfo += model_TemplateInfo.Content; templateUrl += model_TemplateInfo.Content + "<br/>"; templateTitle = model_TemplateInfo.Title; } templateLog += "【同意转出】"; } else { _templateID = 0; templateUrl += "呼叫中心系统有需要您协助处理的问题,"; templateLog += "【提交】"; } templateLog += "发出邮件至【" + userEmail + "】;接收人【" + templateName + "】"; templateUrl += "详情请点击:<br/><a href='" + urlExternal + "'>" + urlHead + "/ExternalTask/ExternalTaskProcess.aspx</a><br/>"; templateUrl += "呼叫中心系统内部人员请访问:<br/><a href='" + urlInternal + "'>" + urlHead + "/TaskManager/TaskProcess.aspx</a>"; model_Email.TemplateID = 0; model_Email.CustID = custID; model_Email.MailTo = userEmail; model_Email.SendTime = DateTime.Now; model_Email.SendContent = templateUrl; model_Email.CreateUserID = int.Parse(RequestLoginEID); BLL.SendEmailLog.Instance.Insert(model_Email); //2根据 客户历史记录信息表中 模板ID来发送模板邮件 BLL.EmailHelper.Instance.SendMail(templateName, templateUrl, "呼叫中心问题处理", new string[] { userEmail }); BLL.Util.InsertUserLog("【外部提交】发送邮件日志表【插入】客户名称:【" + BLL.CustBasicInfo.Instance.GetCustBasicInfo(model_Email.CustID).CustName + "】接收人:【" + templateName + "】邮箱:【" + model_Email.MailTo + "】发送内容:【" + model_Email.SendContent + "】的记录【邮件发送成功】", int.Parse(RequestLoginEID)); }
public int Update(SendEmailLog senbEmailLog) { return(SendEmailLogDal.Ins.Update(senbEmailLog)); }
public int Add(SendEmailLog senbEmailLog) { return(SendEmailLogDal.Ins.Add(senbEmailLog)); }
public async Task <int> AddAsync(SendEmailLog senbEmailLog) { return(await SendEmailLogDal.Ins.AddAsync(senbEmailLog)); }
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" })); }