示例#1
0
        /// <summary>
        ///   Create instance of EmailService with specified providers
        /// </summary>
        /// <param name="mailProvider"></param>
        /// <param name="templateProvider"></param>
        /// <param name="emailTemplateConfiguration"></param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="EmailSettingsException"></exception>
        public EmailService(IMailProvider mailProvider, IMessageTemplateProvider templateProvider,
                            IEmailTemplateConfiguration emailTemplateConfiguration)
        {
            _log = LogManager.GetLogger(GetType());

            if (mailProvider == null)
            {
                throw new ArgumentNullException(nameof(mailProvider));
            }
            if (emailTemplateConfiguration == null)
            {
                throw new ArgumentNullException(nameof(emailTemplateConfiguration));
            }
            _emailSettings = new Settings().EmailSettings;

            if (_emailSettings == null)
            {
                throw new EmailSettingsException();
            }

            _mailProvider               = mailProvider;
            _templateProvider           = templateProvider;
            _emailTemplateConfiguration = emailTemplateConfiguration;
            _engineService              = RazorEngineService.Create((ITemplateServiceConfiguration)_emailTemplateConfiguration);
        }
        /// <summary>
        /// Default configuration constructor
        /// </summary>
        /// <param name="emailsTemplatesFolder"></param>
        public RazorEngineEmailTemplateConfiguration(IEmailTemplateConfiguration basEmailTemplateConfiguration)
        {
            if (string.IsNullOrEmpty(basEmailTemplateConfiguration.TemplateFolder))
            {
                var directoryInfo = new FileInfo(Assembly.GetEntryAssembly().Location).Directory;
                if (directoryInfo != null)
                {
                    TemplateFolder = directoryInfo.FullName;
                }
            }
            else
            {
                TemplateFolder = basEmailTemplateConfiguration.TemplateFolder;
            }

            if (!Directory.Exists(TemplateFolder))
            {
                throw new DirectoryNotFoundException($"Template directory {TemplateFolder} doesn't exists.");
            }

            TemplateManager = new DelegateTemplateManager(name =>
            {
                var templatePath = Path.Combine(TemplateFolder, name);
                using (var reader = new StreamReader(templatePath))
                {
                    return(reader.ReadToEnd());
                }
            });
        }
 public RazorLightMessageProvider(IEmailTemplateConfiguration templateConfiguration)
 {
     _razorEngine = new RazorLightEngineBuilder()
                    .UseFilesystemProject(templateConfiguration.TemplateFolder)
                    .UseMemoryCachingProvider()
                    .Build();
 }
示例#4
0
        /// <summary>
        ///   Create instance of EmailService with specified providers
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="configuration"></param>
        /// <param name="mailProvider"></param>
        /// <param name="templateProvider"></param>
        /// <param name="emailTemplateConfiguration"></param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="EmailSettingsException"></exception>
        public EmailService(ILogger <EmailService> logger, IConfiguration configuration, IMailProvider mailProvider,
                            IMessageTemplateProvider templateProvider, IEmailTemplateConfiguration emailTemplateConfiguration, IMessageProvider messageProvider)
        {
            _logger        = logger;
            _configuration = configuration;

            var section = _configuration.GetSection("gaia:emailSettings");

            //if (section?.Value == null)
            //{
            //	throw new EmailSettingsException();
            //}

            _emailSettings = new EmailSettings();
            section.Bind(_emailSettings);

            _mailProvider               = mailProvider ?? throw new ArgumentNullException(nameof(mailProvider));
            _templateProvider           = templateProvider ?? throw new ArgumentNullException(nameof(templateProvider));
            _emailTemplateConfiguration = emailTemplateConfiguration ?? throw new ArgumentNullException(nameof(emailTemplateConfiguration));
            _messageProvider            = messageProvider ?? throw new ArgumentNullException(nameof(messageProvider));
        }
 public RazorEngineMessageProvider(IEmailTemplateConfiguration templateConfiguration)
 {
     _emailTemplateConfiguration = templateConfiguration ?? throw new ArgumentNullException(nameof(templateConfiguration));
     _engineService = RazorEngineService.Create(new RazorEngineEmailTemplateConfiguration(_emailTemplateConfiguration));
 }