From 96192e2e06087b0214e551dca127ade72885d655 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Tue, 19 Aug 2025 13:16:37 -0400 Subject: [PATCH] add additional SSL connection options for SMTP --- Oqtane.Client/Modules/Admin/Site/Index.razor | 17 +++++++----- .../Resources/Modules/Admin/Site/Index.resx | 19 ++++++++++++-- .../Infrastructure/Jobs/NotificationJob.cs | 26 +++++++++++++++++-- 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/Oqtane.Client/Modules/Admin/Site/Index.razor b/Oqtane.Client/Modules/Admin/Site/Index.razor index 115f29a0..7e1385ff 100644 --- a/Oqtane.Client/Modules/Admin/Site/Index.razor +++ b/Oqtane.Client/Modules/Admin/Site/Index.razor @@ -224,11 +224,14 @@
- +
- + + + + +
@@ -504,7 +507,7 @@ private string _smtpauthentication = "Basic"; private string _smtphost = string.Empty; private string _smtpport = string.Empty; - private string _smtpssl = "True"; + private string _smtpssl = "Auto"; private string _smtpusername = string.Empty; private string _smtppassword = string.Empty; private string _smtppasswordtype = "password"; @@ -613,7 +616,9 @@ { _smtphost = SettingService.GetSetting(settings, "SMTPHost", string.Empty); _smtpport = SettingService.GetSetting(settings, "SMTPPort", string.Empty); - _smtpssl = SettingService.GetSetting(settings, "SMTPSSL", "False"); + _smtpssl = SettingService.GetSetting(settings, "SMTPSSL", "Auto"); + if (_smtpssl == "True") _smtpssl = "SslOnConnect"; + if (_smtpssl == "False") _smtpssl = "StartTlsWhenAvailable"; _smtpauthentication = SettingService.GetSetting(settings, "SMTPAuthentication", "Basic"); _smtpusername = SettingService.GetSetting(settings, "SMTPUsername", string.Empty); _smtppassword = SettingService.GetSetting(settings, "SMTPPassword", string.Empty); diff --git a/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx b/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx index 97e4e8f3..5379db80 100644 --- a/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx +++ b/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx @@ -193,7 +193,7 @@ Enter the port number for the SMTP server. Please note this field is required if you provide a host name. - Specify if SSL is required for your SMTP server + Specify the type of SSL connection for your SMTP server Enter the username for your SMTP account @@ -241,7 +241,7 @@ Port: - SSL Required: + SSL Options: Username: @@ -489,4 +489,19 @@ The Authority Url for the SMTP provider + + None + + + Automatic + + + Upgrade To TLS + + + Require SSL/TLS + + + Use TLS When Available + \ No newline at end of file diff --git a/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs b/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs index 6b755e89..65b53cc0 100644 --- a/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs +++ b/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs @@ -81,9 +81,31 @@ namespace Oqtane.Infrastructure // construct SMTP Client using var client = new SmtpClient(); + var secureSocketOptions = SecureSocketOptions.Auto; + switch (settingRepository.GetSettingValue(settings, "SMTPSSL", "Auto")) + { + case "None": + secureSocketOptions = SecureSocketOptions.None; + break; + case "Auto": + secureSocketOptions = SecureSocketOptions.Auto; + break; + case "StartTls": + secureSocketOptions = SecureSocketOptions.StartTls; + break; + case "SslOnConnect": + case "True": // legacy setting value + secureSocketOptions = SecureSocketOptions.SslOnConnect; + break; + case "StartTlsWhenAvailable": + case "False": // legacy setting value + secureSocketOptions = SecureSocketOptions.StartTlsWhenAvailable; + break; + } + await client.ConnectAsync(settingRepository.GetSettingValue(settings, "SMTPHost", ""), - int.Parse(settingRepository.GetSettingValue(settings, "SMTPPort", "")), - bool.Parse(settingRepository.GetSettingValue(settings, "SMTPSSL", "False")) ? SecureSocketOptions.StartTls : SecureSocketOptions.None); + int.Parse(settingRepository.GetSettingValue(settings, "SMTPPort", "")), + secureSocketOptions); if (settingRepository.GetSettingValue(settings, "SMTPAuthentication", "Basic") == "Basic") {