Esempio n. 1
0
        async Task <EmailSettingsViewModel> GetModel()
        {
            var settings = await _emailSettingsStore.GetAsync();

            if (settings != null)
            {
                return(new EmailSettingsViewModel()
                {
                    SmtpSettings = new SmtpSettingsViewModel()
                    {
                        DefaultFrom = settings.SmtpSettings.DefaultFrom,
                        Host = settings.SmtpSettings.Host,
                        Port = settings.SmtpSettings.Port,
                        UserName = settings.SmtpSettings.UserName,
                        Password = settings.SmtpSettings.Password,
                        RequireCredentials = settings.SmtpSettings.RequireCredentials,
                        EnableSsl = settings.SmtpSettings.EnableSsl,
                        PollInterval = settings.SmtpSettings.PollingInterval,
                        BatchSize = settings.SmtpSettings.BatchSize,
                        SendAttempts = settings.SmtpSettings.SendAttempts,
                        EnablePolling = settings.SmtpSettings.EnablePolling
                    }
                });
            }

            // return default settings
            return(new EmailSettingsViewModel()
            {
                SmtpSettings = new SmtpSettingsViewModel()
            });
        }
Esempio n. 2
0
        public void Configure(SmtpSettings options)
        {
            var settings = _emailSettingsStore
                           .GetAsync()
                           .GetAwaiter()
                           .GetResult();

            // We have no settings to configure

            var smtpSettings = settings?.SmtpSettings;

            if (smtpSettings != null)
            {
                options.DefaultFrom             = smtpSettings.DefaultFrom;
                options.DeliveryMethod          = smtpSettings.DeliveryMethod;
                options.PickupDirectoryLocation = smtpSettings.PickupDirectoryLocation;
                options.Host                  = smtpSettings.Host;
                options.Port                  = smtpSettings.Port;
                options.EnableSsl             = smtpSettings.EnableSsl;
                options.RequireCredentials    = smtpSettings.RequireCredentials;
                options.UseDefaultCredentials = smtpSettings.UseDefaultCredentials;
                options.UserName              = smtpSettings.UserName;
                options.BatchSize             = smtpSettings.BatchSize;
                options.SendAttempts          = smtpSettings.SendAttempts;
                options.PollingInterval       = smtpSettings.PollingInterval;
                options.EnablePolling         = smtpSettings.EnablePolling;

                // Decrypt the password
                if (!String.IsNullOrWhiteSpace(smtpSettings.Password))
                {
                    try
                    {
                        options.Password = _encrypter.Decrypt(smtpSettings.Password);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the SMTP password. {e.Message}");
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public void Configure(SmtpSettings options)
        {
            var settings = _emailSettingsStore
                           .GetAsync()
                           .GetAwaiter()
                           .GetResult();

            // We have no settings to configure

            var smtpSettings = settings?.SmtpSettings;

            if (smtpSettings != null)
            {
                options.DefaultFrom             = smtpSettings.DefaultFrom;
                options.DeliveryMethod          = smtpSettings.DeliveryMethod;
                options.PickupDirectoryLocation = smtpSettings.PickupDirectoryLocation;
                options.Host                  = smtpSettings.Host;
                options.Port                  = smtpSettings.Port;
                options.EnableSsl             = smtpSettings.EnableSsl;
                options.RequireCredentials    = smtpSettings.RequireCredentials;
                options.UseDefaultCredentials = smtpSettings.UseDefaultCredentials;
                options.UserName              = smtpSettings.UserName;

                // Decrypt the password
                if (!String.IsNullOrWhiteSpace(smtpSettings.Password))
                {
                    try
                    {
                        var protector = _dataProtectionProvider.CreateProtector(nameof(SmtpSettings));
                        options.Password = protector.Unprotect(smtpSettings.Password);
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e, $"There was a problem decrypting the SMTP password. {e.Message}");
                    }
                }
            }
        }