diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Extensions/EmailQuotaManagementExtensions.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Extensions/EmailQuotaManagementExtensions.cs index 4d2e4915..8087a753 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Extensions/EmailQuotaManagementExtensions.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Extensions/EmailQuotaManagementExtensions.cs @@ -7,8 +7,7 @@ public static class EmailQuotaManagementExtensions { public static void SetEmailQuotaManagementOptionsForUITest( this OrchardCoreUITestExecutorConfiguration configuration, - long maximumEmails, - string emailHost = "localhost") + long maximumEmails) { configuration.OrchardCoreConfiguration.BeforeAppStart += (_, argumentsBuilder) => @@ -18,11 +17,6 @@ public static void SetEmailQuotaManagementOptionsForUITest( "OrchardCore:Lombiq_Hosting_Tenants_EmailQuotaManagement:EmailQuotaPerMonth", maximumEmails); - argumentsBuilder - .AddWithValue( - "OrchardCore:SmtpSettings:Host", - emailHost); - return Task.CompletedTask; }; diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs index 30ee233a..7de7b86b 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs @@ -26,7 +26,7 @@ public static async Task TestEmailQuotaManagementBehaviorAsync( await context.SignInDirectlyAndGoToDashboardAsync(); context.Missing(By.XPath(DashboardExceededMessage)); - await context.ConfigureSmtpPortAsync(publish: false); + await context.GoToEmailSettingsAsync(); CheckEmailsSentWarningMessage(context, exists: moduleShouldInterfere, maximumEmailQuota, 0); await context.ClickReliablyOnAsync(By.ClassName("save")); diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaService.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaService.cs index dc45845a..37f436fd 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaService.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaService.cs @@ -1,9 +1,7 @@ using Lombiq.Hosting.Tenants.EmailQuotaManagement.Models; using Microsoft.AspNetCore.Identity; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Options; using OrchardCore.Email; -using OrchardCore.Environment.Shell.Configuration; using OrchardCore.Modules; using OrchardCore.Security; using OrchardCore.Security.Services; @@ -25,8 +23,8 @@ public class EmailQuotaService : IEmailQuotaService { private readonly ISession _session; private readonly EmailQuotaOptions _emailQuotaOptions; - private readonly IShellConfiguration _shellConfiguration; - private readonly SmtpSettings _smtpOptions; + private readonly DefaultSmtpOptions _defaultSmtpOptions; + private readonly SmtpOptions _smtpOptions; private readonly IClock _clock; private readonly IRoleService _roleService; private readonly UserManager _userManager; @@ -34,15 +32,15 @@ public class EmailQuotaService : IEmailQuotaService public EmailQuotaService( ISession session, IOptions emailQuotaOptions, - IShellConfiguration shellConfiguration, - IOptions smtpOptions, + IOptions defaultSmtpOptions, + IOptions smtpOptions, IClock clock, IRoleService roleService, UserManager userManager) { _session = session; _emailQuotaOptions = emailQuotaOptions.Value; - _shellConfiguration = shellConfiguration; + _defaultSmtpOptions = defaultSmtpOptions.Value; _smtpOptions = smtpOptions.Value; _clock = clock; _roleService = roleService; @@ -66,11 +64,8 @@ public async Task> GetUserEmailsForEmailReminderAsync() return siteOwners.Select(user => (user as User)?.Email); } - public bool ShouldLimitEmails() - { - var originalHost = _shellConfiguration.GetValue("SmtpSettings:Host"); - return originalHost == _smtpOptions.Host; - } + public bool ShouldLimitEmails() => + _defaultSmtpOptions.Host == _smtpOptions.Host || (_defaultSmtpOptions.Host != null && _smtpOptions.Host == null); public async Task IsQuotaOverTheLimitAsync() {