public bool SendMail(int id, string question, string jsonString, string request, string baseUrl, string title) { //获取收件人信息 string strToken = WeChatCommonService.GetWeiXinToken(AppId); var mobile = string.Empty; var obj = MailListApi.GetMember(strToken, ViewBag.LillyId); string receiver = obj != null ? obj.email : ""; var EmailReceiver = ""; var EmailEnableSsl = false; var EmailHost = ""; var EmailPassword = ""; var EmailUserName = ""; var EmailPort = ""; var EmailSender = ""; var EmailEnable = true; var EmailTitle = ""; var EmailTemplate = ""; object jsonResult = null; LogManager.GetLogger(this.GetType()).Debug("request" + request); var js = new JavaScriptSerializer(); jsonResult = js.Deserialize <object>(jsonString); var fullResult = jsonResult as Dictionary <string, object>; if (fullResult != null) { EmailReceiver = fullResult["EmailReceiver"] as string; EmailEnableSsl = bool.Parse(fullResult["EmailEnableSsl"].ToString()); EmailHost = fullResult["EmailHost"] as string; EmailPassword = fullResult["EmailPassword"] as string; EmailUserName = fullResult["EmailUserName"] as string; EmailPort = fullResult["EmailPort"] as string; EmailSender = fullResult["EmailSender"] as string; EmailEnable = bool.Parse(fullResult["EmailEnable"].ToString()); EmailTitle = fullResult["EmailTitle"] as string; EmailTemplate = fullResult["EmailTemplate"] as string; } if (!string.IsNullOrEmpty(EmailTitle)) { //特殊处理EmailTitle if (!string.IsNullOrEmpty(title)) { EmailTitle = string.Format("{0} ({1},{2})", EmailTitle, ViewBag.LillyId, DateTime.Now.ToShortDateString()); } EmailTitle = EmailTitle.Replace("\r", "").Replace("\n", ""); } List <QuestionImagesView> lst = _objImageService.GetListByQuestionID <QuestionImagesView>(id); var attachlink = ""; if (lst != null) { attachlink = lst.Aggregate(attachlink, (current, attach) => string.Format("{0}<a href=\"{1}\">{2}</a>\n", current, string.Format("{0}Common/QuestionFile?id={1}&filename={2}", baseUrl, attach.Id, attach.ImageName), attach.ImageName)); } var userModel = _objUserService.GetBylillyId(ViewBag.LillyId); if (userModel != null) { mobile = userModel.Tel; } var emailContent = EmailTemplate.Replace("#Url#", request).Replace("#Question#", question). Replace("#LillyId#", ViewBag.LillyId).Replace("#Email#", receiver).Replace("#Contact#", mobile) .Replace("#Attachment#", attachlink); var set = new EmailMessageSettingsRecord() { Host = EmailHost, UserName = EmailUserName, Password = EmailPassword, Port = int.Parse(EmailPort), EnableSsl = EmailEnableSsl, Enable = EmailEnable, DeliveryMethod = "Network", Address = EmailSender, RequireCredentials = true }; Task.Run(() => { var ser = new EmailMessageService(set); ser.SendMessage(EmailSender, EmailReceiver, EmailTitle, emailContent.Replace("\r\n", "<br/>").Replace("\n", "<br/>").Replace("\r", "<br/>")); }); return(true); }
public EmailMessageServiceUnitTests() { messageService = new EmailMessageService(); }
private bool SendEmail(MeetingRoomRepairView objModel, int id) { var jsonString = CommonService.GetSysConfig("RoomRepairEmail", ""); string repairType = CommonService.GetSysConfig("RepairType", ""); string title = string.Empty; string content = string.Empty; var EmailReceiver = ""; var EmailEnableSsl = false; var EmailHost = ""; var EmailPassword = ""; var EmailUserName = ""; var EmailPort = ""; var EmailSender = ""; var EmailEnable = true; var EmailTitle = ""; var EmailTemplate = ""; var EmailTemplateOther = ""; object jsonResult = null; var js = new JavaScriptSerializer(); jsonResult = js.Deserialize <object>(jsonString); var fullResult = jsonResult as Dictionary <string, object>; if (fullResult != null) { EmailReceiver = fullResult["EmailReceiver"] as string; EmailEnableSsl = bool.Parse(fullResult["EmailEnableSsl"].ToString()); EmailHost = fullResult["EmailHost"] as string; EmailPassword = fullResult["EmailPassword"] as string; EmailUserName = fullResult["EmailUserName"] as string; EmailPort = fullResult["EmailPort"] as string; EmailSender = fullResult["EmailSender"] as string; EmailEnable = bool.Parse(fullResult["EmailEnable"].ToString()); EmailTitle = fullResult["EmailTitle"] as string; EmailTemplate = fullResult["EmailTemplate"] as string; EmailTemplateOther = fullResult["EmailTemplate-other"] as string; } var set = new EmailMessageSettingsRecord() { Host = EmailHost, UserName = EmailUserName, Password = EmailPassword, Port = int.Parse(EmailPort), EnableSsl = EmailEnableSsl, Enable = EmailEnable, DeliveryMethod = "Network", Address = EmailSender, RequireCredentials = true }; var ser = new EmailMessageService(set); if (objModel != null) { if (string.IsNullOrEmpty(objModel.Comment)) { EmailTemplate = EmailTemplate.Replace("#Location#", objModel.Location).Replace("#RoomName#", objModel.RoomName).Replace("#Type#", RepairType(objModel.Type)) .Replace("#RepairID#", objModel.CreatedUserID).Replace("#RepairName#", objModel.RepairName).Replace("#RepairEmail#", objModel.RepairEmail); ser.SendMessage(EmailSender, EmailReceiver, EmailTitle, EmailTemplate); _Logger.Error <string>(string.Format("SendEmail_meetingRoomRepair:{0}", EmailSender + "/" + EmailTitle + "/" + EmailTemplate)); } else { EmailTemplateOther = EmailTemplateOther.Replace("#Location#", objModel.Location).Replace("#RoomName#", objModel.RoomName).Replace("#Type#", RepairType(objModel.Type)) .Replace("#RepairID#", objModel.CreatedUserID).Replace("#RepairName#", objModel.RepairName).Replace("#RepairEmail#", objModel.RepairEmail).Replace("#RepairComment#", objModel.Comment); ser.SendMessage(EmailSender, EmailReceiver, EmailTitle, EmailTemplateOther); _Logger.Error <string>(string.Format("SendEmail_meetingRoomRepair:{0}", EmailSender + "/" + EmailTitle + "/" + EmailTemplateOther)); } } return(true); }
public bool SendMail(int id, string question, string jsonString, string request, string baseUrl, string title) { //获取收件人信息 var receiver = string.Empty; //For local Testing "*****@*****.**" var objConfig = WeChatCommonService.GetWeChatConfigByID(AppId); string strToken = AccessTokenContainer.TryGetToken(objConfig.WeixinCorpId, objConfig.WeixinCorpSecret); var mobile = string.Empty; #if !DEBUG var obj = MailListApi.GetMember(strToken, ViewBag.WeChatUserID); if (obj != null) { receiver = obj.email; } else { receiver = ""; } #endif var EmailReceiver = ""; var EmailEnableSsl = false; var EmailHost = ""; var EmailPassword = ""; var EmailUserName = ""; var EmailPort = ""; var EmailSender = ""; var EmailEnable = true; var EmailTitle = ""; var EmailTemplate = ""; object jsonResult = null; LogManager.GetLogger(this.GetType()).Debug("request" + request); JavaScriptSerializer js = new JavaScriptSerializer(); jsonResult = js.Deserialize <object>(jsonString); var fullResult = jsonResult as Dictionary <string, object>; if (fullResult != null) { EmailReceiver = fullResult["EmailReceiver"] as string; EmailEnableSsl = bool.Parse(fullResult["EmailEnableSsl"].ToString()); EmailHost = fullResult["EmailHost"] as string; EmailPassword = fullResult["EmailPassword"] as string; EmailUserName = fullResult["EmailUserName"] as string; EmailPort = fullResult["EmailPort"] as string; EmailSender = fullResult["EmailSender"] as string; EmailEnable = bool.Parse(fullResult["EmailEnable"].ToString()); EmailTitle = fullResult["EmailTitle"] as string; EmailTemplate = fullResult["EmailTemplate"] as string; } if (!string.IsNullOrEmpty(EmailTitle)) { //特殊处理EmailTitle if (!string.IsNullOrEmpty(title)) { EmailTitle = string.Format("{0} ({1},{2})", EmailTitle, ViewBag.WeChatUserID, DateTime.Now.ToShortDateString()); } EmailTitle = EmailTitle.Replace("\r", "").Replace("\n", ""); } List <QuestionImagesView> lst = _objImageService.GetListByQuestionID <QuestionImagesView>(id); var attachlink = ""; if (lst != null || lst.Count > 0) { foreach (var attach in lst) { attachlink = string.Format("{0}<a href=\"{1}\">{2}</a>\n", attachlink, string.Format("{0}Common/QuestionFile?id={1}&filename={2}", baseUrl, attach.Id, attach.ImageName), attach.ImageName); } } var userModel = _objUserService.GetByWeChatUserID(ViewBag.WeChatUserID); if (userModel != null) { mobile = userModel.Tel; } var EmailContent = EmailTemplate.Replace("#Url#", request).Replace("#Question#", question). Replace("#WeChatUserID#", ViewBag.WeChatUserID).Replace("#Email#", receiver).Replace("#Contact#", mobile) .Replace("#Attachment#", attachlink); EmailMessageSettingsRecord set = new EmailMessageSettingsRecord() { Host = EmailHost, UserName = EmailUserName, Password = EmailPassword, Port = int.Parse(EmailPort), EnableSsl = EmailEnableSsl, Enable = EmailEnable, DeliveryMethod = "Network", Address = EmailSender, RequireCredentials = true }; Task.Run(() => { EmailMessageService ser = new EmailMessageService(set); ser.SendMessage(EmailSender, EmailReceiver, EmailTitle, EmailContent.Replace("\r\n", "<br/>").Replace("\n", "<br/>").Replace("\r", "<br/>")); }); return(true); }
public bool SendMail(string LillyId, int AppId, string question, string jsonString, string request, string baseUrl, string title, bool sfMail = false) { //获取收件人信息 string strToken = WeChatCommonService.GetWeiXinToken(AppId); var mobile = string.Empty; var obj = MailListApi.GetMember(strToken, LillyId); string receiver = obj != null ? obj.email : ""; var EmailReceiver = ""; var EmailEnableSsl = false; var EmailHost = ""; var EmailPassword = ""; var EmailUserName = ""; var EmailPort = ""; var EmailSender = ""; var EmailEnable = true; var EmailTitle = ""; var EmailTemplate = ""; object jsonResult = null; jsonResult = JsonHelper.FromJson <Dictionary <string, object> >(jsonString); var fullResult = jsonResult as Dictionary <string, object>; if (fullResult != null) { EmailReceiver = fullResult["EmailReceiver"] as string; EmailEnableSsl = bool.Parse(fullResult["EmailEnableSsl"].ToString()); EmailHost = fullResult["EmailHost"] as string; EmailPassword = fullResult["EmailPassword"] as string; EmailUserName = fullResult["EmailUserName"] as string; EmailPort = fullResult["EmailPort"] as string; EmailSender = fullResult["EmailSender"] as string; EmailEnable = bool.Parse(fullResult["EmailEnable"].ToString()); EmailTitle = fullResult["EmailTitle"] as string; EmailTemplate = fullResult["EmailTemplate"] as string; } if (sfMail) { EmailReceiver = obj != null ? obj.email : ""; } if (!string.IsNullOrEmpty(EmailTitle)) { //特殊处理EmailTitle if (!string.IsNullOrEmpty(title)) { EmailTitle = string.Format("{0} ({1},{2})", EmailTitle, LillyId, DateTime.Now.ToShortDateString()); } EmailTitle = EmailTitle.Replace("\r", "").Replace("\n", ""); } var emailContent = EmailTemplate.Replace("#Url#", request).Replace("#Question#", question). Replace("#LillyId#", LillyId).Replace("#Email#", receiver); var set = new EmailMessageSettingsRecord() { Host = EmailHost, UserName = EmailUserName, Password = EmailPassword, Port = int.Parse(EmailPort), EnableSsl = EmailEnableSsl, Enable = EmailEnable, DeliveryMethod = "Network", Address = EmailSender, RequireCredentials = true }; Task.Run(() => { var ser = new EmailMessageService(set); ser.SendMessage(EmailSender, EmailReceiver, EmailTitle, emailContent.Replace("\r\n", "<br/>").Replace("\n", "<br/>").Replace("\r", "<br/>")); }); return(true); }
private bool SendEmail(int id, string type) { var baseUrl = CommonService.GetSysConfig("WeChatUrl", ""); baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); var jsonString = CommonService.GetSysConfig("HSEEmail", ""); var appId = CommonService.GetSysConfig(HseAppIdKey, ""); var lillyId = CommonService.GetSysConfig("HSELillyID", ""); var list = new HseInjuredSafetyIncidentView(); var imgList = new HseSafetyReportImagesView(); string title = string.Empty; string content = string.Empty; string attachlink = string.Empty; string patientName = string.Empty; string patientlillyID = string.Empty; var EmailReceiver = ""; var EmailEnableSsl = false; var EmailHost = ""; var EmailPassword = ""; var EmailUserName = ""; var EmailPort = ""; var EmailSender = ""; var EmailEnable = true; var EmailTitle = ""; var EmailTemplate = ""; object jsonResult = null; var js = new JavaScriptSerializer(); jsonResult = js.Deserialize <object>(jsonString); var fullResult = jsonResult as Dictionary <string, object>; if (fullResult != null) { EmailReceiver = fullResult["EmailReceiver"] as string; EmailEnableSsl = bool.Parse(fullResult["EmailEnableSsl"].ToString()); EmailHost = fullResult["EmailHost"] as string; EmailPassword = fullResult["EmailPassword"] as string; EmailUserName = fullResult["EmailUserName"] as string; EmailPort = fullResult["EmailPort"] as string; EmailSender = fullResult["EmailSender"] as string; EmailEnable = bool.Parse(fullResult["EmailEnable"].ToString()); EmailTitle = fullResult["EmailTitle"] as string; EmailTemplate = fullResult["EmailTemplate"] as string; } var safetyReport = _hseSafetyTroubleService.GetSafetyReportById(id, type); if (safetyReport != null) { string location = string.Empty; string injurySites = string.Empty; if (string.IsNullOrEmpty(safetyReport.Location)) { location = safetyReport.OtherLocation; } else { location = safetyReport.Location; } if (string.IsNullOrEmpty(safetyReport.InjurySites)) { injurySites = safetyReport.OtherInjurySites; } else { injurySites = safetyReport.InjurySites; } if (safetyReport.SafetyReportImages != null) { attachlink = safetyReport.SafetyReportImages.Aggregate(attachlink, (current, attach) => string.Format("{0}<a href=\"{1}\">{2}</a><br>", current, string.Format("{0}/SafetyReportImage/HseSafetyReportFile?id={1}&filename={2}", baseUrl, attach.Id, attach.ImageName), attach.ImageName.Replace("/temp/", ""))); } if (type == "SafetyTrouble") { title = "安全隐患事件提醒"; content = "您好:<br>微信中有员工已提交安全隐患事件,请尽快查看。谢谢!<br><br>汇报安全隐患:<br>汇报人姓名:" + safetyReport.ReportedUserName + "<br>" + "汇报人LillyID:" + safetyReport.CreatedUserID + "<br>发生日期:" + safetyReport.OccurrenceDate.ToString("yyyy-MM-dd") + "<br>" + "隐患发生地:" + location + "<br>" + "安全隐患描述:" + safetyReport.Description + "<br>附件:" + attachlink + ""; } else { if (safetyReport.PatientInfo == "1") { patientName = safetyReport.ReportedUserName; patientlillyID = safetyReport.CreatedUserID; } else { patientName = safetyReport.PatientName; patientlillyID = safetyReport.PatientLillyId; } title = "安全汇报事件提醒"; content = "您好:<br>微信中有员工已提交安全汇报事件,请尽快查看。谢谢!<br><br>汇报受伤或安全事故:<br>受伤人姓名:" + patientName + "<br>" + "受伤人ID:" + patientlillyID + "<br>发生日期:" + safetyReport.OccurrenceDate.ToString("yyyy-MM-dd") + "<br>" + "事件发生地:" + location + "<br>" + "受伤类型:" + safetyReport.InjuredType + "<br>受伤部位:" + injurySites + "<br>" + "事件简述:" + safetyReport.Description + "<br>附件:" + attachlink + ""; } EmailTitle = EmailTitle.Replace("#Title#", title); EmailTemplate = EmailTemplate.Replace("#Content#", content); } var set = new EmailMessageSettingsRecord() { Host = EmailHost, UserName = EmailUserName, Password = EmailPassword, Port = int.Parse(EmailPort), EnableSsl = EmailEnableSsl, Enable = EmailEnable, DeliveryMethod = "Network", Address = EmailSender, RequireCredentials = true }; var ser = new EmailMessageService(set); ser.SendMessage(EmailSender, EmailReceiver, EmailTitle, EmailTemplate); _Logger.Error <string>(string.Format("SendEmail_safetyReport:{0}", EmailSender + "/" + EmailTitle + "/" + EmailTemplate)); return(true); }
public EmailController(EmailMessageService emailMessageService) { _emailMessageService = emailMessageService; }