From e65baae814822faca954f75af0e0e2a7d8b74c66 Mon Sep 17 00:00:00 2001 From: Michael Latouche Date: Tue, 14 Dec 2021 13:56:10 +0100 Subject: [PATCH] Remove the need of Smtp.Host config when using PickupDirectoryLocation (#11548) --- .../Configuration/Models/GlobalSettings.cs | 6 +++++- src/Umbraco.Infrastructure/Mail/EmailSender.cs | 13 +++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs index c88083027488..94b8d88ed322 100644 --- a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs @@ -159,6 +159,10 @@ public class GlobalSettings public bool IsSmtpServerConfigured => !string.IsNullOrWhiteSpace(Smtp?.Host); /// + /// Gets a value indicating whether there is a physical pickup directory configured. + /// + public bool IsPickupDirectoryLocationConfigured => !string.IsNullOrWhiteSpace(Smtp?.PickupDirectoryLocation); + /// Gets a value indicating whether TinyMCE scripting sanitization should be applied /// [DefaultValue(StaticSanitizeTinyMce)] @@ -174,4 +178,4 @@ public class GlobalSettings [DefaultValue(StaticSqlWriteLockTimeOut)] public TimeSpan SqlWriteLockTimeOut { get; } = TimeSpan.Parse(StaticSqlWriteLockTimeOut); } -} +} \ No newline at end of file diff --git a/src/Umbraco.Infrastructure/Mail/EmailSender.cs b/src/Umbraco.Infrastructure/Mail/EmailSender.cs index 854c2fb51eb3..5da5e5097df6 100644 --- a/src/Umbraco.Infrastructure/Mail/EmailSender.cs +++ b/src/Umbraco.Infrastructure/Mail/EmailSender.cs @@ -75,15 +75,13 @@ private async Task SendAsyncInternal(EmailMessage message, string emailType, boo } } - var isPickupDirectoryConfigured = !string.IsNullOrWhiteSpace(_globalSettings.Smtp?.PickupDirectoryLocation); - - if (_globalSettings.IsSmtpServerConfigured == false && !isPickupDirectoryConfigured) + if (!_globalSettings.IsSmtpServerConfigured && !_globalSettings.IsPickupDirectoryLocationConfigured) { _logger.LogDebug("Could not send email for {Subject}. It was not handled by a notification handler and there is no SMTP configured.", message.Subject); return; } - if (isPickupDirectoryConfigured && !string.IsNullOrWhiteSpace(_globalSettings.Smtp?.From)) + if (_globalSettings.IsPickupDirectoryLocationConfigured && !string.IsNullOrWhiteSpace(_globalSettings.Smtp?.From)) { // The following code snippet is the recommended way to handle PickupDirectoryLocation. // See more https://github.com/jstedfast/MailKit/blob/master/FAQ.md#q-how-can-i-send-email-to-a-specifiedpickupdirectory @@ -154,7 +152,10 @@ await client.ConnectAsync(_globalSettings.Smtp.Host, /// /// /// We assume this is possible if either an event handler is registered or an smtp server is configured + /// or a pickup directory location is configured /// - public bool CanSendRequiredEmail() => _globalSettings.IsSmtpServerConfigured || _notificationHandlerRegistered; + public bool CanSendRequiredEmail() => _globalSettings.IsSmtpServerConfigured + || _globalSettings.IsPickupDirectoryLocationConfigured + || _notificationHandlerRegistered; } -} +} \ No newline at end of file