public async Task SendMail() { if (!await new NotificationDAO().IsSend()) { #region *) Field var userprofile = Session["UserProfile"] as UserProfileVM; var auditUploadModel = new ActionPlanDAO().CheckLateOnUpdateData(userprofile.User.ID); var model = new ActionPlanDAO().CheckDeadline(); #endregion #region 1) Late On Update Thread lateOnTask = new Thread(async() => await CheckLateOnUpdate(auditUploadModel)); lateOnTask.Start(); #endregion #region 2) Check Late On Task Thread lateOnUpload = new Thread(async() => await CheckLateOnTask(model)); lateOnUpload.Start(); #endregion #region *) Thông báo để biết gửi mail hay chưa var itemSendMail = new StateSendMail(); await new NotificationDAO().AddSendMail(itemSendMail); new ErrorMessageDAO().Add(new ErrorMessage { Function = "Send Mail", Name = "[KPI System] Late on task, [KPI System] Late on upload data" }); #endregion } }
public async Task <bool> AddSendMail(StateSendMail stateSendMail) { try { _dbContext.StateSendMails.Add(stateSendMail); await _dbContext.SaveChangesAsync(); return(true); } catch (Exception) { return(false); } }
private async Task SendMail() { if (!await _notificationService.IsSend()) { #region *) Field string token = Request.Headers["Authorization"]; var userID = Extensions.GetDecodeTokenByProperty(token, "nameid").ToInt(); var auditUploadModel = _actionPlanService.CheckLateOnUpdateData(userID); var model = _actionPlanService.CheckDeadline(); #endregion #region 1) Late On Update Thread lateOnTask = new Thread(async() => await CheckLateOnUpdate(auditUploadModel)); lateOnTask.Start(); #endregion #region 2) Check Late On Task Thread lateOnUpload = new Thread(async() => await CheckLateOnTask(model)); lateOnUpload.Start(); #endregion #region *) Thông báo để biết gửi mail hay chưa var itemSendMail = new StateSendMail(); await _notificationService.AddSendMail(itemSendMail); await _errorMessageService.Add(new ErrorMessage { Function = "Send Mail", Name = "[KPI System] Late on task, [KPI System] Late on upload data" }); #endregion } }
public async Task SendMail() { if (!await new NotificationDAO().IsSend()) { #region *) Field var userprofile = Session["UserProfile"] as UserProfileVM; string host = ConfigurationManager.AppSettings["Http"].ToSafetyString(); string contentForAuditUpload = System.IO.File.ReadAllText(Server.MapPath("~/Templates/LateOnUpDateData.html")); contentForAuditUpload = contentForAuditUpload.Replace("{{{content}}}", @"<b style='color:red'>Late On Update Data</b><br/>Your KPIs have expired as below list: "); string contentForDeadline = System.IO.File.ReadAllText(Server.MapPath("~/Templates/LateOnTask.html")); contentForDeadline = contentForDeadline.Replace("{{{content}}}", @"<b style='color:red'>Late On Task</b><br/>Your task have expired as below list: "); var htmlForUpload = string.Empty; var htmlForDeadLine = string.Empty; var count = 0; var auditUploadModel = new ActionPlanDAO().CheckLateOnUpdateData(userprofile.User.ID); var model = new ActionPlanDAO().CheckDeadline(); #endregion #region 1) Late On Update if (await new SettingDAO().IsSendMail("CHECKLATEONUPDATEDATA")) { foreach (var item2 in auditUploadModel.Item1) { count++; htmlForUpload += @"<tr> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{no}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{area}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{ockpicode}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{kpiname}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{year}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{deadline}}</td> </tr>" .Replace("{{no}}", count.ToSafetyString()) .Replace("{{area}}", item2[3].ToSafetyString()) .Replace("{{kpiname}}", item2[0].ToSafetyString()) .Replace("{{ockpicode}}", item2[2].ToSafetyString()) .Replace("{{year}}", item2[4].ToSafetyString()) .Replace("{{deadline}}", item2[1].ToSafetyString()); } contentForAuditUpload = contentForAuditUpload.Replace("{{{html-template}}}", htmlForUpload); if (auditUploadModel.Item1.Count > 0) { Commons.SendMail(auditUploadModel.Item2.Select(x => x.Email).ToList(), "[KPI System] Late on upload data", contentForAuditUpload, "Late on upload data"); } } #endregion #region 2) Check Dead Line if (await new SettingDAO().IsSendMail("CHECKDEADLINE")) { foreach (var item in model.Item1) { //string content = "Please note that the action plan we are overdue on " + item.Deadline; count++; htmlForDeadLine += @"<tr> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{no}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{kpiname}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{deadline}}</td> </tr>" .Replace("{{no}}", count.ToString()) .Replace("{{kpiname}}", item[0].ToSafetyString()) .Replace("{{deadline}}", item[1].ToSafetyString("MM/dd/yyyy")); } contentForDeadline = contentForDeadline.Replace("{{{html-template}}}", htmlForDeadLine); if (model.Item1.Count > 0) { Commons.SendMail(model.Item2.Select(x => x.Email).ToList(), "[KPI System] Late on task", contentForDeadline, "Late on task "); } } #endregion #region *) Thông báo để biết gửi mail hay chưa var itemSendMail = new StateSendMail(); await new NotificationDAO().AddSendMail(itemSendMail); new ErrorMessageDAO().Add(new ErrorMessage { Function = "Send Mail", Name = "[KPI System] Late on task, [KPI System] Late on upload data" }); #endregion } }
private async Task <bool> SendMail2() { string URL = _configuaration.GetSection("AppSettings:URL").ToSafetyString(); string token = Request.Headers["Authorization"]; var userID = Extensions.DecodeToken(token).FirstOrDefault(x => x.Type == "nameid").Value.ToInt(); if (!await _notificationService.IsSend()) { string content2 = System.IO.File.ReadAllText(URL + "/Templates/LateOnUpDateData.html"); content2 = content2.Replace("{{{content}}}", @"<b style='color:red'>Late On Update Data</b><br/>Your KPIs have expired as below list: "); string content = System.IO.File.ReadAllText(URL + "/Templates/LateOnTask.html"); content = content.Replace("{{{content}}}", @"<b style='color:red'>Late On Task</b><br/>Your task have expired as below list: "); var html = string.Empty; var html2 = string.Empty; var count = 0; var model2 = _actionPlanService.CheckLateOnUpdateData(); var model = _actionPlanService.CheckDeadline(); if (await _settingService.IsSendMail("CHECKLATEONUPDATEDATA")) { foreach (var item2 in model2.Item1) { count++; html += @"<tr> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{no}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{area}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{ockpicode}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{kpiname}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{year}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{deadline}}</td> </tr>" .Replace("{{no}}", count.ToSafetyString()) .Replace("{{area}}", item2[3].ToSafetyString()) .Replace("{{kpiname}}", item2[0].ToSafetyString()) .Replace("{{ockpicode}}", item2[2].ToSafetyString()) .Replace("{{year}}", item2[4].ToSafetyString()) .Replace("{{deadline}}", item2[1].ToSafetyString()); } content2 = content2.Replace("{{{html-template}}}", html); } if (await _settingService.IsSendMail("CHECKDEADLINE")) { foreach (var item in model.Item1) { //string content = "Please note that the action plan we are overdue on " + item.Deadline; count++; html2 += @"<tr> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{no}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{kpiname}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{deadline}}</td> </tr>" .Replace("{{no}}", count.ToString()) .Replace("{{kpiname}}", item[0].ToSafetyString()) .Replace("{{deadline}}", item[1].ToSafetyString("MM/dd/yyyy")); } content = content.Replace("{{{html-template}}}", html2); await _mailHelper.SendEmailRange(model.Item2.Select(x => x.Email).ToList(), "[KPI System] Late on task", content); } var itemSendMail = new StateSendMail(); await _notificationService.AddSendMail(itemSendMail); int hh = _configuration.GetSection("AppSettings:hh").ToInt(); int mm = _configuration.GetSection("AppSettings:mm").ToInt(); await _errorMessageService.Add(new ErrorMessage { Function = "Test window service " + hh + ":" + mm, Name = "EmailJob" }); } return(true); }
public async Task Execute(IJobExecutionContext context) { //throw new NotImplementedException(); string from = ConfigurationManager.AppSettings["FromEmailAddress"].ToSafetyString(); string host = ConfigurationManager.AppSettings["Http"].ToSafetyString(); string content2 = System.IO.File.ReadAllText(host + "/Templates/LateOnUpDateData.html"); content2 = content2.Replace("{{{content}}}", "Your below KPIs have expired: "); string content = System.IO.File.ReadAllText(host + "/Templates/LateOnTask.html"); content = content.Replace("{{{content}}}", "Your below KPIs have expired: "); var html = string.Empty; var count = 0; var model2 = new ActionPlanDAO().CheckLateOnUpdateData(1); var model = new ActionPlanDAO().CheckDeadline(); if (await new SettingDAO().IsSendMail("CHECKLATEONUPDATEDATA")) { foreach (var item2 in model2.Item1) { count++; html += @"<tr> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{no}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{kpiname}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{year}}</td> </tr>" .Replace("{{no}}", count.ToSafetyString()) .Replace("{{kpiname}}", item2[0].ToSafetyString()) .Replace("{{year}}", item2[1].ToSafetyString()); content2 = content2.Replace("{{{html-template}}}", html); } Commons.SendMail(model2.Item2.Select(x => x.Email).ToList(), "[KPI System] Late on upload data", content2, "Late on upload data"); } if (await new SettingDAO().IsSendMail("CHECKDEADLINE")) { foreach (var item in model.Item1) { //string content = "Please note that the action plan we are overdue on " + item.Deadline; count++; html += @"<tr> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{no}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{kpiname}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{deadline}}</td> </tr>" .Replace("{{no}}", count.ToString()) .Replace("{{kpiname}}", item[0].ToSafetyString()) .Replace("{{deadline}}", item[1].ToSafetyString("MM/dd/yyyy")); content = content.Replace("{{{html-template}}}", html); } Commons.SendMail(model.Item2.Select(x => x.Email).ToList(), "[KPI System] Late on task", content, "Late on task "); } var itemSendMail = new StateSendMail(); await new NotificationDAO().AddSendMail(itemSendMail); var hh = ConfigurationManager.AppSettings["hh"].ToInt(); var mm = ConfigurationManager.AppSettings["mm"].ToInt(); var db = new KPIDbContext(); var items = new ErrorMessage() { Function = "Test window service " + hh + ":" + mm, Name = "EmailJob" }; db.ErrorMessages.Add(items); await db.SaveChangesAsync(); db.Dispose(); }