From 91c53098552c93ab547678056355e4235c17db36 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Mon, 28 Jul 2025 10:26:18 -0400 Subject: [PATCH] fix #5372 - add support for sending SMTP emails using OAuth --- Oqtane.Client/Modules/Admin/Site/Index.razor | 252 ++++++++++++------ .../Resources/Modules/Admin/Site/Index.resx | 48 +++- 2 files changed, 215 insertions(+), 85 deletions(-) diff --git a/Oqtane.Client/Modules/Admin/Site/Index.razor b/Oqtane.Client/Modules/Admin/Site/Index.razor index fcc9557f..8b7c9ad2 100644 --- a/Oqtane.Client/Modules/Admin/Site/Index.razor +++ b/Oqtane.Client/Modules/Admin/Site/Index.razor @@ -193,80 +193,125 @@
-
-
+
- @Localizer["Smtp.Required.EnableNotificationJob"]
-
-
-
- -
- -
-
-
- -
- -
-
-
- -
-
-
- -
- -
-
-
- -
-
- - + @if (_smtpenabled == "True") + { +
+
+
+
+ @Localizer["Smtp.Required.EnableNotificationJob"]
-
-
- -
- +
+ +
+ +
-
-
- -
- +
+ +
+ +
-
-
- -
- +
+ +
+ +
-
-
- -
- +
+ +
+ +
-
- -

+ @if (_smtpauthentication == "Basic") + { +
+ +
+ +
+
+
+ +
+
+ + +
+
+
+
+ +
+ +
+
+ } + else + { +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ + +
+
+
+
+ +
+ +
+
+ } +
+ +
+ +
+
+
+ +
+ +
+
+ +

+ }
@@ -454,16 +499,23 @@ private string _headcontent = string.Empty; private string _bodycontent = string.Empty; + private string _smtpenabled = "False"; + private string _smtpauthentication = "Basic"; private string _smtphost = string.Empty; private string _smtpport = string.Empty; - private string _smtpssl = "False"; + private string _smtpssl = "True"; private string _smtpusername = string.Empty; private string _smtppassword = string.Empty; private string _smtppasswordtype = "password"; private string _togglesmtppassword = string.Empty; + private string _smtpauthority = string.Empty; + private string _smtpclientid = string.Empty; + private string _smtpclientsecret = string.Empty; + private string _smtpclientsecrettype = "password"; + private string _togglesmtpclientsecret = string.Empty; + private string _smtpscopes = string.Empty; private string _smtpsender = string.Empty; private string _smtprelay = "False"; - private string _smtpenabled = "True"; private int _retention = 30; private string _pwaisenabled; @@ -555,15 +607,21 @@ _bodycontent = site.BodyContent; // SMTP + _smtpenabled = SettingService.GetSetting(settings, "SMTPEnabled", "False"); _smtphost = SettingService.GetSetting(settings, "SMTPHost", string.Empty); _smtpport = SettingService.GetSetting(settings, "SMTPPort", string.Empty); _smtpssl = SettingService.GetSetting(settings, "SMTPSSL", "False"); + _smtpauthentication = SettingService.GetSetting(settings, "SMTPAuthentication", "Basic"); _smtpusername = SettingService.GetSetting(settings, "SMTPUsername", string.Empty); _smtppassword = SettingService.GetSetting(settings, "SMTPPassword", string.Empty); _togglesmtppassword = SharedLocalizer["ShowPassword"]; + _smtpauthority = SettingService.GetSetting(settings, "SMTPAuthority", string.Empty); + _smtpclientid = SettingService.GetSetting(settings, "SMTPClientId", string.Empty); + _smtpclientsecret = SettingService.GetSetting(settings, "SMTPClientSecret", string.Empty); + _togglesmtpclientsecret = SharedLocalizer["ShowPassword"]; + _smtpscopes = SettingService.GetSetting(settings, "SMTPScopes", string.Empty); _smtpsender = SettingService.GetSetting(settings, "SMTPSender", string.Empty); _smtprelay = SettingService.GetSetting(settings, "SMTPRelay", "False"); - _smtpenabled = SettingService.GetSetting(settings, "SMTPEnabled", "True"); _retention = int.Parse(SettingService.GetSetting(settings, "NotificationRetention", "30")); // PWA @@ -744,8 +802,13 @@ settings = SettingService.SetSetting(settings, "SMTPHost", _smtphost, true); settings = SettingService.SetSetting(settings, "SMTPPort", _smtpport, true); settings = SettingService.SetSetting(settings, "SMTPSSL", _smtpssl, true); + settings = SettingService.SetSetting(settings, "SMTPAuthentication", _smtpauthentication, true); settings = SettingService.SetSetting(settings, "SMTPUsername", _smtpusername, true); settings = SettingService.SetSetting(settings, "SMTPPassword", _smtppassword, true); + settings = SettingService.SetSetting(settings, "SMTPAuthority", _smtpauthority, true); + settings = SettingService.SetSetting(settings, "SMTPClientId", _smtpclientid, true); + settings = SettingService.SetSetting(settings, "SMTPClientSecret", _smtpclientsecret, true); + settings = SettingService.SetSetting(settings, "SMTPScopes", _smtpscopes, true); settings = SettingService.SetSetting(settings, "SMTPSender", _smtpsender, true); settings = SettingService.SetSetting(settings, "SMTPRelay", _smtprelay, true); settings = SettingService.SetSetting(settings, "SMTPEnabled", _smtpenabled, true); @@ -812,6 +875,46 @@ } } + private void SMTPAuthenticationChanged(ChangeEventArgs e) + { + _smtpauthentication = (string)e.Value; + StateHasChanged(); + } + + private void SMTPEnabledChanged(ChangeEventArgs e) + { + _smtpenabled = (string)e.Value; + StateHasChanged(); + } + + private void ToggleSMTPPassword() + { + if (_smtppasswordtype == "password") + { + _smtppasswordtype = "text"; + _togglesmtppassword = SharedLocalizer["HidePassword"]; + } + else + { + _smtppasswordtype = "password"; + _togglesmtppassword = SharedLocalizer["ShowPassword"]; + } + } + + private void ToggleSmtpClientSecret() + { + if (_smtpclientsecrettype == "password") + { + _smtpclientsecrettype = "text"; + _togglesmtpclientsecret = SharedLocalizer["HidePassword"]; + } + else + { + _smtpclientsecrettype = "password"; + _togglesmtpclientsecret = SharedLocalizer["ShowPassword"]; + } + } + private async Task SendEmail() { if (_smtphost != "" && _smtpport != "" && _smtpsender != "") @@ -822,8 +925,13 @@ settings = SettingService.SetSetting(settings, "SMTPHost", _smtphost, true); settings = SettingService.SetSetting(settings, "SMTPPort", _smtpport, true); settings = SettingService.SetSetting(settings, "SMTPSSL", _smtpssl, true); + settings = SettingService.SetSetting(settings, "SMTPAuthentication", _smtpauthentication, true); settings = SettingService.SetSetting(settings, "SMTPUsername", _smtpusername, true); settings = SettingService.SetSetting(settings, "SMTPPassword", _smtppassword, true); + settings = SettingService.SetSetting(settings, "SMTPAuthority", _smtpauthority, true); + settings = SettingService.SetSetting(settings, "SMTPClientId", _smtpclientid, true); + settings = SettingService.SetSetting(settings, "SMTPClientSecret", _smtpclientsecret, true); + settings = SettingService.SetSetting(settings, "SMTPScopes", _smtpscopes, true); settings = SettingService.SetSetting(settings, "SMTPSender", _smtpsender, true); await SettingService.UpdateSiteSettingsAsync(settings, PageState.Site.SiteId); await logger.LogInformation("Site SMTP Settings Saved"); @@ -844,20 +952,6 @@ } } - private void ToggleSMTPPassword() - { - if (_smtppasswordtype == "password") - { - _smtppasswordtype = "text"; - _togglesmtppassword = SharedLocalizer["HidePassword"]; - } - else - { - _smtppasswordtype = "password"; - _togglesmtppassword = SharedLocalizer["ShowPassword"]; - } - } - private async Task GetAliases() { if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) diff --git a/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx b/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx index acfd022e..7e2fae82 100644 --- a/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx +++ b/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx @@ -192,7 +192,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 @@ -202,7 +202,7 @@ Enter the password for your SMTP account - Enter the email which emails will be sent from. Please note that this email address may need to be authorized with the SMTP server. + Enter the email address which emails will be sent from. Please note that this email address usually needs to be authorized with the SMTP server. Select whether you would like this site to be available as a Progressive Web Application (PWA) @@ -240,8 +240,8 @@ Port: - - SSL Enabled: + + SSL Required: Username: @@ -372,10 +372,10 @@ Page Content - + Specify if SMTP is enabled for this site - + Enabled? @@ -453,4 +453,40 @@ The default time zone for the site + + Basic + + + OAuth + + + Authentication: + + + Specify the SMTP authentication type + + + Client ID: + + + The Client ID for the SMTP provider + + + Client Secret: + + + The Client Secret for the SMTP provider + + + Scopes: + + + A list of Scopes for the SMTP provider (separated by commas) + + + Authority Url: + + + The Authority Url for the SMTP provider + \ No newline at end of file