Merge pull request #5516 from sbwalker/dev
add additional SSL connection options for SMTP
This commit is contained in:
@ -224,11 +224,14 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="smtpssl" HelpText="Specify if SSL is required for your SMTP server" ResourceKey="SmtpSSL">SSL Required: </Label>
|
||||
<Label Class="col-sm-3" For="smtpssl" HelpText="Specify the type of SSL connection for your SMTP server" ResourceKey="SmtpSSL">SSL Options: </Label>
|
||||
<div class="col-sm-9">
|
||||
<select id="smtpssl" class="form-select" @bind="@_smtpssl" >
|
||||
<option value="True">@SharedLocalizer["Yes"]</option>
|
||||
<option value="False">@SharedLocalizer["No"]</option>
|
||||
<select id="smtpssl" class="form-select" @bind="@_smtpssl">
|
||||
<option value="None">@Localizer["None"]</option>
|
||||
<option value="Auto">@Localizer["Auto"]</option>
|
||||
<option value="StartTls">@Localizer["StartTls"]</option>
|
||||
<option value="SslOnConnect">@Localizer["SslOnConnect"]</option>
|
||||
<option value="StartTlsWhenAvailable">@Localizer["StartTlsWhenAvailable"]</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@ -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);
|
||||
|
@ -193,7 +193,7 @@
|
||||
<value>Enter the port number for the SMTP server. Please note this field is required if you provide a host name.</value>
|
||||
</data>
|
||||
<data name="SmtpSSL.HelpText" xml:space="preserve">
|
||||
<value>Specify if SSL is required for your SMTP server</value>
|
||||
<value>Specify the type of SSL connection for your SMTP server</value>
|
||||
</data>
|
||||
<data name="SmtpUsername.HelpText" xml:space="preserve">
|
||||
<value>Enter the username for your SMTP account</value>
|
||||
@ -241,7 +241,7 @@
|
||||
<value>Port: </value>
|
||||
</data>
|
||||
<data name="SmtpSSL.Text" xml:space="preserve">
|
||||
<value>SSL Required: </value>
|
||||
<value>SSL Options:</value>
|
||||
</data>
|
||||
<data name="SmtpUsername.Text" xml:space="preserve">
|
||||
<value>Username: </value>
|
||||
@ -489,4 +489,19 @@
|
||||
<data name="SmtpAuthority.HelpText" xml:space="preserve">
|
||||
<value>The Authority Url for the SMTP provider</value>
|
||||
</data>
|
||||
<data name="None" xml:space="preserve">
|
||||
<value>None</value>
|
||||
</data>
|
||||
<data name="Auto" xml:space="preserve">
|
||||
<value>Automatic</value>
|
||||
</data>
|
||||
<data name="StartTls" xml:space="preserve">
|
||||
<value>Upgrade To TLS</value>
|
||||
</data>
|
||||
<data name="SslOnConnect" xml:space="preserve">
|
||||
<value>Require SSL/TLS</value>
|
||||
</data>
|
||||
<data name="StartTlsWhenAvailable" xml:space="preserve">
|
||||
<value>Use TLS When Available</value>
|
||||
</data>
|
||||
</root>
|
@ -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")
|
||||
{
|
||||
|
Reference in New Issue
Block a user