Example #1
0
        /// <summary>
        /// 发送Email
        /// </summary>
        /// <param name="email">接收人Email</param>
        /// <param name="subject">Email标题</param>
        /// <param name="body">Email内容</param>
        /// <returns></returns>
        public Task SendEmailAsync(string email, string subject, string body)
        {
            ESoftorOptions    options    = _provider.GetESoftorOptions();
            MailSenderOptions mailSender = options.MailSender;

            if (mailSender == null || mailSender.Host == null || mailSender.Host.Contains("请替换"))
            {
                throw new ESoftorException("邮件发送选项不存在,请在appsetting.json配置Hybrid.MailSender节点");
            }

            string host        = mailSender.Host,
                   displayName = mailSender.DisplayName,
                   userName    = mailSender.UserName,
                   password    = mailSender.Password;
            SmtpClient client  = new SmtpClient(host)
            {
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(userName, password)
            };

            string      fromEmail = userName.Contains("@") ? userName : "******".FormatWith(userName, client.Host.Replace("smtp.", ""));
            MailMessage mail      = new MailMessage
            {
                From       = new MailAddress(fromEmail, displayName),
                Subject    = subject,
                Body       = body,
                IsBodyHtml = true
            };

            mail.To.Add(email);
            return(client.SendMailAsync(mail));
        }
Example #2
0
        /// <summary>
        /// 重写以获取是否开启延迟加载代理特性
        /// </summary>
        /// <returns></returns>
        public override bool LazyLoadingProxiesEnabled()
        {
            if (_serviceProvider == null)
            {
                IConfiguration configuration = Singleton <IConfiguration> .Instance;
                return(configuration["ESoftor:DbContexts:SqlServer:LazyLoadingProxiesEnabled"].CastTo(false));
            }
            ESoftorOptions          options        = _serviceProvider.GetESoftorOptions();
            ESoftorDbContextOptions contextOptions = options.GetDbContextOptions(typeof(DefaultDbContext));

            if (contextOptions == null)
            {
                throw new ESoftorException($"上下文“{typeof(DefaultDbContext)}”的配置信息不存在");
            }

            return(contextOptions.LazyLoadingProxiesEnabled);
        }
Example #3
0
        public override string GetConnectionString()
        {
            if (_serviceProvider == null)
            {
                IConfiguration configuration = Singleton <IConfiguration> .Instance;
                string         str           = configuration["ESoftor:DbContexts:SqlServer:ConnectionString"]
                                               ?? configuration["ConnectionStrings:DefaultDbContext"];
                return(str);
            }
            ESoftorOptions          options        = _serviceProvider.GetESoftorOptions();
            ESoftorDbContextOptions contextOptions = options.GetDbContextOptions(typeof(DefaultDbContext));

            if (contextOptions == null)
            {
                throw new ESoftorException($"上下文“{typeof(DefaultDbContext)}”的配置信息不存在");
            }
            return(contextOptions.ConnectionString);
        }