public JsonResult CallEmailService(SendEmailData email) { Common.Data.JsonData json = new Common.Data.JsonData() { Result = true }; //查询邮件账户 EmailSystemSetting setting = RefreshAppSetting.GetSystemEmailAccount(); IEmailDataService es = IocMvcFactoryHelper.GetInterface <IEmailDataService>(); es.LogPath = InitAppSetting.LogPath; AppEmailData data = new AppEmailData() { Body = email.Body, From = setting.EmailAccount, Mailer = email.Mailer, To = email.To, Subject = email.Subject }; if (!string.IsNullOrEmpty(email.SendTime)) { data.SendTime = Convert.ToDateTime(email.SendTime); } json.Success = es.SendEmail(setting, data, setting.Smtp); json.AttachData = email; return(Json(json)); }
public EmailService( IEmailDataService emailDataService, IConfigService configService, ISmtpClientFactory smtpClientFactory, ILogger <EmailService> logger ) { this.emailDataService = emailDataService; this.configService = configService; this.smtpClientFactory = smtpClientFactory; this.logger = logger; }
public void LoopSendEmali(List <EmailAccount> accs, string subject) {//每日激活邮件账户 //查询邮件账户列表 string dir = LogPrepare.GetLogPath(); ELogType el = ELogType.EmailLog; string file = LogPrepare.GetLogName(el); IEmailDataService emailService = IocMvcFactoryHelper.GetInterface <IEmailDataService>(); foreach (var item in accs) { string time = DateTime.Now.ToString(Common.Data.CommonFormat.DateTimeFormat); string title = "[HrApp Everyday active]"; try { //使用邮件账户进行邮件发送 short smtp = item.Smtp; //拼接发送的邮件内容 EmailSystemSetting ess = new EmailSystemSetting() { EmailAccount = item.Account, EmailAuthortyCode = item.AuthortyCode, EmailHost = item.SmtpHost, EmailHostPort = EmailSystemSetting.GetHostPortSmtp(smtp) }; ess.Smtp = (EnumSMTP)smtp; StringBuilder body = new StringBuilder(); body.AppendLine(" Guid:<br/> "); for (int i = 0; i < 10; i++) { body.AppendLine(string.Format(" {0}<br/> ", Guid.NewGuid().ToString().ToUpper())); } string text = string.Format("{0} <br/> smtp= {1}<br/> time= {2} <br/>{3} ", title, item.Account, time, body.ToString()); string receive = InitAppSetting.Global.ReceiverInEmailActive; AppEmailData emailData = new AppEmailData() { EmailCreateTime = DateTime.Now, To = string.IsNullOrEmpty(receive) ? "*****@*****.**" : receive, Subject = subject, From = item.Account, Body = text }; emailService.SendEmail(ess, emailData, ess.Smtp); LoggerWriter.CreateLogFile(title + "[Success]" + time, dir, el, file, true); } catch (Exception ex) { title += ex.Message; LoggerWriter.CreateLogFile(title + "[Error]" + time, dir, el, file, true); } } }
public override void Execute(INotification notification) { switch (notification.Type) { case AppNotify.Get_AllEmailSMTP: Task.Factory.StartNew(() => { IEmailDataService email = IocMvcFactoryHelper.GetInterface <IEmailDataService>(); List <EmailAccount> accs = email.QueryEmailAccountInDB(); FacadeFactory.FacadeInstance.SendNotification(AppNotify.GlobalExecuteEvent, accs, AppNotify.Back_AllEmailSMTP); }); break; } }
public void Setup() { emailDataService = A.Fake <IEmailDataService>(); configService = A.Fake <IConfigService>(); var smtpClientFactory = A.Fake <ISmtpClientFactory>(); smtpClient = A.Fake <ISmtpClient>(); A.CallTo(() => smtpClientFactory.GetSmtpClient()).Returns(smtpClient); A.CallTo(() => configService.GetConfigValue(ConfigService.MailPort)).Returns("25"); A.CallTo(() => configService.GetConfigValue(ConfigService.MailUsername)).Returns("username"); A.CallTo(() => configService.GetConfigValue(ConfigService.MailPassword)).Returns("password"); A.CallTo(() => configService.GetConfigValue(ConfigService.MailServer)).Returns("smtp.example.com"); A.CallTo(() => configService.GetConfigValue(ConfigService.MailFromAddress)).Returns("*****@*****.**"); var logger = A.Fake <ILogger <EmailService> >(); emailService = new EmailService(emailDataService, configService, smtpClientFactory, logger); }
public EmailAdminDataController(IEmailDataService emailDataService) { _emailDataService = emailDataService; }
public EmailController(IEmailDataService emailDataService, IManageEmailService manageEmailService) { _emailDataService = emailDataService; _manageEmailService = manageEmailService; }
public EmailClientDataController(IEmailDataService emailDataService) { _emailDataService = emailDataService; }
static void OrmIocFactory() { if (propertyVal.Count > 0) {//存储字典非空出来 } string connString = InitAppSetting.LogicDBConnString; InterfaceIocHelper ioc = new InterfaceIocHelper(); string dir = NowAppDirHelper.GetNowAppDir(AppCategory.WebApp); // 获取到的目录 E:\Code\DayDayStudy\PickUpData\HRApp\HRApp.Web\ string dllDir = dir + "bin\\"; #region dll路径配置 Dictionary <MvcLevel, AssemblyData> mvc = new Dictionary <MvcLevel, AssemblyData>(); mvc.Add(MvcLevel.DAL, new AssemblyData() { AssemblyName = "HRApp.Infrastructure.dll", Namespace = "HRApp.Infrastructure" }); mvc.Add(MvcLevel.Bll, new AssemblyData() { AssemblyName = "HRApp.ApplicationService.dll", Namespace = "HRApp.ApplicationService" }); #endregion propertyVal.Add("SqlConnString", connString); propertyVal.Add(typeof(IEnumDataRepository).Name + ".SqlConnString", InitAppSetting.AccountDBConnString); //账号库 propertyVal.Add(typeof(IEnumDataService).Name + ".SqlConnString", InitAppSetting.AccountDBConnString); //账号库 propertyVal.Add(typeof(IAppAccountRepository).Name + ".SqlConnString", InitAppSetting.AccountDBConnString); //账号库 propertyVal.Add(typeof(IAppAccountService).Name + ".SqlConnString", InitAppSetting.AccountDBConnString); //账号库 propertyVal.Add(typeof(IMenuRepository).Name + ".SqlConnString", InitAppSetting.AccountDBConnString); //账号库 propertyVal.Add(typeof(IDataFromOtherRepository).Name + ".SqlConnString", InitAppSetting.QueryUinDB); //这个是用于系统中查询其他库的数据切换操作 #region dal层属性 #region Account DB IEnumDataRepository enumDal = ioc.IocConvert <IEnumDataRepository>(dllDir, mvc[MvcLevel.DAL].AssemblyName, mvc[MvcLevel.DAL].Namespace, typeof(EnumDataRepository).Name); ioc.IocFillProperty(enumDal, propertyVal); IAppAccountRepository accountDal = ioc.IocConvert <IAppAccountRepository>(dllDir, mvc[MvcLevel.DAL].AssemblyName, mvc[MvcLevel.DAL].Namespace, typeof(AppAccountRepository).Name); ioc.IocFillProperty(accountDal, propertyVal); IMenuRepository menuDal = ioc.IocConvert <IMenuRepository>(dllDir, mvc[MvcLevel.DAL].AssemblyName, mvc[MvcLevel.DAL].Namespace, typeof(MenuRepository).Name); ioc.IocFillProperty(menuDal, propertyVal); #endregion #region log --all ILogDataRepository logDal = ioc.IocConvert <ILogDataRepository>(dllDir, mvc[MvcLevel.DAL].AssemblyName, mvc[MvcLevel.DAL].Namespace, typeof(LogDataRepository).Name); ioc.IocFillProperty(logDal, propertyVal); #endregion IAppRepository appDal = ioc.IocConvert <IHRApp.Infrastructure.IAppRepository>(dllDir, mvc[MvcLevel.DAL].AssemblyName, mvc[MvcLevel.DAL].Namespace, typeof(AppRepository).Name); ioc.IocFillProperty <IAppRepository, IAppRepository>(appDal, propertyVal); IAppSettingRepository appSettingDal = ioc.IocConvert <IAppSettingRepository>(dllDir, mvc[MvcLevel.DAL].AssemblyName, mvc[MvcLevel.DAL].Namespace, typeof(AppSettingRepository).Name); ioc.IocFillProperty(appSettingDal, propertyVal); IOrganizationRepository organzeDal = ioc.IocConvert <IOrganizationRepository>(dllDir, mvc[MvcLevel.DAL].AssemblyName, mvc[MvcLevel.DAL].Namespace, typeof(OrganizationRepository).Name); ioc.IocFillProperty(organzeDal, propertyVal); IContactDataRepository contacterDal = ioc.IocConvert <IContactDataRepository>(dllDir, mvc[MvcLevel.DAL].AssemblyName, mvc[MvcLevel.DAL].Namespace, typeof(ContactDataRepository).Name); ioc.IocFillProperty(contacterDal, propertyVal); IMaybeSpecialRepository maybeSpecialDal = ioc.IocConvert <IMaybeSpecialRepository>(dllDir, mvc[MvcLevel.DAL].AssemblyName, mvc[MvcLevel.DAL].Namespace, typeof(MaybeSpecialRepository).Name); ioc.IocFillProperty <IMaybeSpecialRepository>(maybeSpecialDal, propertyVal); ISpecialSpellNameRepository speicalSpellDal = ioc.IocConvert <ISpecialSpellNameRepository>(dllDir, mvc[MvcLevel.DAL].AssemblyName, mvc[MvcLevel.DAL].Namespace, typeof(SpecialSpellNameRepository).Name); ioc.IocFillProperty <ISpecialSpellNameRepository>(speicalSpellDal, propertyVal); IDataFromOtherRepository dataFormOtherDal = ioc.IocConvert <IDataFromOtherRepository>(dllDir, mvc[MvcLevel.DAL].AssemblyName, mvc[MvcLevel.DAL].Namespace, typeof(DataFromOtherRepository).Name); ioc.IocFillProperty <IDataFromOtherRepository>(dataFormOtherDal, propertyVal); IReportEnumDataRepository reportDal = ioc.IocConvert <IReportEnumDataRepository>(dllDir, mvc[MvcLevel.DAL].AssemblyName, mvc[MvcLevel.DAL].Namespace, typeof(ReportEnumDataRepository).Name); ioc.IocFillProperty <IReportEnumDataRepository>(reportDal, propertyVal); IRelyTableRepository relyDal = ioc.IocConvert <IRelyTableRepository>(dllDir, mvc[MvcLevel.DAL].AssemblyName, mvc[MvcLevel.DAL].Namespace, typeof(RelyTableRepository).Name); ioc.IocFillProperty <IRelyTableRepository>(relyDal, propertyVal); IEmailDataRepository emailDal = ioc.IocConvert <IEmailDataRepository>(dllDir, mvc[MvcLevel.DAL].AssemblyName, mvc[MvcLevel.DAL].Namespace, typeof(EmailDataRepository).Name); ioc.IocFillProperty <IEmailDataRepository>(emailDal, propertyVal); #endregion #region orm中dal层实例化存储到字典中 propertyVal.Add(typeof(ILogDataRepository).Name, logDal); propertyVal.Add(typeof(IEnumDataRepository).Name, enumDal); propertyVal.Add(typeof(IAppAccountRepository).Name, accountDal); propertyVal.Add(typeof(IAppRepository).Name, appDal); propertyVal.Add(typeof(IAppSettingRepository).Name, appSettingDal); propertyVal.Add(typeof(IMenuRepository).Name, menuDal); propertyVal.Add(typeof(IOrganizationRepository).Name, organzeDal); propertyVal.Add(typeof(IContactDataRepository).Name, contacterDal); propertyVal.Add(typeof(IMaybeSpecialRepository).Name, maybeSpecialDal); propertyVal.Add(typeof(ISpecialSpellNameRepository).Name, speicalSpellDal); propertyVal.Add(typeof(IDataFromOtherRepository).Name, dataFormOtherDal); propertyVal.Add(typeof(IReportEnumDataRepository).Name, reportDal); propertyVal.Add(typeof(IRelyTableRepository).Name, relyDal); propertyVal.Add(typeof(IEmailDataRepository).Name, emailDal); #endregion #region 业务层 IEnumDataService enumBll = ioc.IocConvert <IEnumDataService>(dllDir, mvc[MvcLevel.Bll].AssemblyName, mvc[MvcLevel.Bll].Namespace, typeof(EnumDataService).Name); ioc.IocFillProperty <IEnumDataService, EnumDataService>(enumBll, propertyVal); propertyVal.Add(typeof(IEnumDataService).Name, enumBll); IAppAccountService accountBll = ioc.IocConvert <IAppAccountService>(dllDir, mvc[MvcLevel.Bll].AssemblyName, mvc[MvcLevel.Bll].Namespace, typeof(AppAccountService).Name); ioc.IocFillProperty <IAppAccountService, AppAccountService>(accountBll, propertyVal); propertyVal.Add(typeof(IAppAccountService).Name, accountBll); //构造函数的参数注入 判断构造函数的参数是否需要进行注入 IAppDataService appService = ioc.IocConvert <IAppDataService>(dllDir, mvc[MvcLevel.Bll].AssemblyName, mvc[MvcLevel.Bll].Namespace, typeof(AppDataService).Name); ioc.IocFillProperty <IAppDataService, AppDataService>(appService, propertyVal); propertyVal.Add(typeof(IAppDataService).Name, appService); IAppSettingService appSetService = ioc.IocConvert <IAppSettingService>(dllDir, mvc[MvcLevel.Bll].AssemblyName, mvc[MvcLevel.Bll].Namespace, typeof(AppSettingService).Name); ioc.IocFillProperty <IAppSettingService, AppSettingService>(appSetService, propertyVal); //属性和字段注入 propertyVal.Add(typeof(IAppSettingService).Name, appSetService); IMenuService menuService = ioc.IocConvert <IMenuService>(dllDir, mvc[MvcLevel.Bll].AssemblyName, mvc[MvcLevel.Bll].Namespace, typeof(MenuService).Name); ioc.IocFillProperty <IMenuService, MenuService>(menuService, propertyVal); propertyVal.Add(typeof(IMenuService).Name, menuService); IOrganizationService organzeService = ioc.IocConvert <IOrganizationService>(dllDir, mvc[MvcLevel.Bll].AssemblyName, mvc[MvcLevel.Bll].Namespace, typeof(OrganizationService).Name); ioc.IocFillProperty <IOrganizationService, OrganizationService>(organzeService, propertyVal); propertyVal.Add(typeof(IOrganizationService).Name, organzeService); IContactDataService contactService = ioc.IocConvert <IContactDataService>(dllDir, mvc[MvcLevel.Bll].AssemblyName, mvc[MvcLevel.Bll].Namespace, typeof(ContactDataService).Name); ioc.IocFillProperty <IContactDataService, ContactDataService>(contactService, propertyVal); propertyVal.Add(typeof(IContactDataService).Name, contactService); IMaybeSpecialService maybeSpeiclaService = ioc.IocConvert <IMaybeSpecialService>(dllDir, mvc[MvcLevel.Bll].AssemblyName, mvc[MvcLevel.Bll].Namespace, typeof(MaybeSpecialService).Name); ioc.IocFillProperty <IMaybeSpecialService, MaybeSpecialService>(maybeSpeiclaService, propertyVal); propertyVal.Add(typeof(IMaybeSpecialService).Name, maybeSpeiclaService); ISpecialSpellNameService specialSpellService = ioc.IocConvert <ISpecialSpellNameService>(dllDir, mvc[MvcLevel.Bll].AssemblyName, mvc[MvcLevel.Bll].Namespace, typeof(SpecialSpellNameService).Name); ioc.IocFillProperty <ISpecialSpellNameService, SpecialSpellNameService>(specialSpellService, propertyVal); propertyVal.Add(typeof(ISpecialSpellNameService).Name, specialSpellService); IDataFromOtherService dataFormService = ioc.IocConvert <IDataFromOtherService>(dllDir, mvc[MvcLevel.Bll].AssemblyName, mvc[MvcLevel.Bll].Namespace, typeof(DataFromOtherService).Name); ioc.IocFillProperty <IDataFromOtherService, DataFromOtherService>(dataFormService, propertyVal); propertyVal.Add(typeof(IDataFromOtherService).Name, dataFormService); IReportEnumDataService reportBll = ioc.IocConvert <IReportEnumDataService>(dllDir, mvc[MvcLevel.Bll].AssemblyName, mvc[MvcLevel.Bll].Namespace, typeof(ReportEnumDataService).Name); ioc.IocFillProperty <IReportEnumDataService, ReportEnumDataService>(reportBll, propertyVal); propertyVal.Add(typeof(IReportEnumDataService).Name, reportBll); IRelyTableService relyBll = ioc.IocConvert <IRelyTableService>(dllDir, mvc[MvcLevel.Bll].AssemblyName, mvc[MvcLevel.Bll].Namespace, typeof(RelyTableService).Name); ioc.IocFillProperty <IRelyTableService>(relyBll, propertyVal); propertyVal.Add(typeof(IRelyTableService).Name, relyBll); IEmailDataService emailBll = ioc.IocConvert <IEmailDataService>(dllDir, mvc[MvcLevel.Bll].AssemblyName, mvc[MvcLevel.Bll].Namespace, typeof(EmailDataService).Name); ioc.IocFillProperty <IEmailDataService>(emailBll, propertyVal); propertyVal.Add(typeof(IEmailDataService).Name, emailBll); ILogDataService logBll = ioc.IocConvert <ILogDataService>(dllDir, mvc[MvcLevel.Bll].AssemblyName, mvc[MvcLevel.Bll].Namespace, typeof(LogDataService).Name); ioc.IocFillProperty <ILogDataService>(logBll, propertyVal); propertyVal.Add(typeof(ILogDataService).Name, logBll); #endregion }
private void TestEmail(string title) { string text = "使用代码进行邮箱测试功能"; string time = DateTime.Now.ToString(Common.Data.CommonFormat.DateTimeFormat); text += "<br/>邮件创建时间 :" + time; for (int i = 0; i < 10; i++) { text += string.Format("<br/> Guid{0}={1}", (i + 1), Guid.NewGuid().ToString().ToUpper()); } string logDir = LogPrepare.GetLogPath(); ELogType el = ELogType.EmailLog; string day = LogPrepare.GetLogName(el); try { Dictionary <string, string> emailSetting = InitAppSetting.AppSettingItemsInDB; string type = emailSetting[EAppSetting.SMTP.ToString()]; string sendBy = emailSetting[EAppSetting.SystemEmailSendBy.ToString()]; string authorCode = emailSetting[EAppSetting.SystemEmailSMPTAuthor.ToString()]; string smtpClient = emailSetting[EAppSetting.SMTPClient.ToString()]; EnumSMTP smtp; Enum.TryParse(type, out smtp); AppEmailData emailData = new AppEmailData() { EmailCreateTime = DateTime.Now, To = InitAppSetting.Global.ReceiverInEmailActive,// "*****@*****.**", Subject = title, From = sendBy, Body = text }; EmailSystemSetting setting = new Model.EmailSystemSetting() { EmailHostPort = smtp == EnumSMTP.NETS163? 25:587, EmailAuthortyCode = authorCode, EmailAccount = sendBy, EmailHost = smtpClient }; #region 直接发送,不存储【测试可用】 /* * EmailData email = new EmailData() * { * EmailTo =InitAppSetting.Global.ReceiverInEmailActive, * EmailSubject = title, * EmailBody = text, * CreateTime = DateTime.Now, * EmailFrom = sendBy * }; * EmailService es = new EmailService(smtpClient, sendBy, authorCode, 25, true); * es.SendEmailBy163(email); * */ #endregion IEmailDataService eds = IocMvcFactoryHelper.GetInterface <IEmailDataService>(); eds.SendEmail(setting, emailData, smtp); LoggerWriter.CreateLogFile(time + "\t[OK]进行邮件测试", logDir, el, day, true); } catch (Exception ex) { string msg = time + "\t[ Error]" + ex.Message; LoggerWriter.CreateLogFile(msg, logDir, el, day, true); } }
public RecordsTempController(IRecordTempService recordTempService, IEmailDataService emailDataService, IEmailSendingService emailSendingService) { _recordTempService = recordTempService; _emailDataService = emailDataService; _emailSendingService = emailSendingService; }
public EmailRepository() { emailDataService = new EmailDataService(); }