Skip to content

Commit

Permalink
Add option to disable certificate revocation check when sending email.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Apr 20, 2021
1 parent 71d3a56 commit 1b4ba49
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
9 changes: 5 additions & 4 deletions Server/Pages/GetSupport.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,26 @@ public IActionResult OnGet()
return Page();
}

public async Task<IActionResult> OnPost(string deviceID)
public async Task<IActionResult> OnPost(string deviceId)
{
if (!ModelState.IsValid)
{
return Page();
}

var orgID = _dataService.GetDevice(deviceID)?.OrganizationID;
var orgID = _dataService.GetDevice(deviceId)?.OrganizationID;

var alertParts = new string[]
{
$"{Input.Name} is requesting support.",
$"Device ID: {deviceId}",
$"Email: {Input.Email}.",
$"Phone: {Input.Phone}.",
$"Chat OK: {Input.ChatResponseOk}."
};

var alertMessage = string.Join(" ", alertParts);
await _dataService.AddAlert(deviceID, orgID, alertMessage);
await _dataService.AddAlert(deviceId, orgID, alertMessage);

var orgUsers = await _dataService.GetAllUsersInOrganization(orgID);
var emailMessage = string.Join("<br />", alertParts);
Expand All @@ -57,7 +58,7 @@ public async Task<IActionResult> OnPost(string deviceID)

StatusMessage = "We got it! Someone will contact you soon.";

return RedirectToPage("GetSupport", new { deviceID });
return RedirectToPage("GetSupport", new { deviceId });
}

public class InputModel
Expand Down
10 changes: 10 additions & 0 deletions Server/Pages/ServerConfig.razor
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,16 @@
<br />
<ValidationMessage For="() => Input.SmtpPort" />
</div>
<div class="form-group">
<label class="control-label">SMTP Check Certificate Revocation</label>
<div class="small text-muted">
This sometimes needs to be disabled for Let's Encrypt certificates.
</div>
<br />
<InputCheckbox @bind-Value="Input.SmtpCheckCertificateRevocation" autocomplete="off" />
<br />
<ValidationMessage For="() => Input.SmtpCheckCertificateRevocation" />
</div>
<div class="form-group">
<label class="control-label">SMTP Local Domain</label>
<br />
Expand Down
5 changes: 4 additions & 1 deletion Server/Pages/ServerConfig.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public class AppSettingsModel
[Display(Name = "SMTP Local Domain")]
public string SmtpLocalDomain { get; set; }

[Display(Name = "SMTP Check Certificate Revocation")]
public bool SmtpCheckCertificateRevocation { get; set; }

[Display(Name = "SMTP Password")]
public string SmtpPassword { get; set; }

Expand Down Expand Up @@ -320,7 +323,7 @@ private async Task SaveAndTestSmtpSettings()
}
else
{
ToastService.ShowToast("Error sending email. Check the server logs for details.");
ToastService.ShowToast("Error sending email. Check the server logs for details.", classString: "bg-error");
_alertMessage = "Error sending email. Check the server logs for details.";
}
}
Expand Down
2 changes: 2 additions & 0 deletions Server/Services/ApplicationConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public interface IApplicationConfig
string SmtpPassword { get; }
int SmtpPort { get; }
string SmtpUserName { get; }
bool SmtpCheckCertificateRevocation { get; }
Theme Theme { get; }
string[] TrustedCorsOrigins { get; }
bool UseHsts { get; }
Expand Down Expand Up @@ -72,6 +73,7 @@ public ApplicationConfig(IConfiguration config)
public string SmtpPassword => Config["ApplicationOptions:SmtpPassword"];
public int SmtpPort => int.Parse(Config["ApplicationOptions:SmtpPort"] ?? "25");
public string SmtpUserName => Config["ApplicationOptions:SmtpUserName"];
public bool SmtpCheckCertificateRevocation => bool.Parse(Config["ApplicationOptions:SmtpCheckCertificateRevocation"] ?? "true");
public Theme Theme => Enum.Parse<Theme>(Config["ApplicationOptions:Theme"] ?? "Dark", true);
public string[] TrustedCorsOrigins => Config.GetSection("ApplicationOptions:TrustedCorsOrigins").Get<string[]>() ?? System.Array.Empty<string>();
public bool UseHsts => bool.Parse(Config["ApplicationOptions:UseHsts"] ?? "false");
Expand Down
3 changes: 3 additions & 0 deletions Server/Services/EmailSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public async Task<bool> SendEmailAsync(string toEmail, string replyTo, string su
{
client.LocalDomain = AppConfig.SmtpLocalDomain;
}

client.CheckCertificateRevocation = AppConfig.SmtpCheckCertificateRevocation;

await client.ConnectAsync(AppConfig.SmtpHost, AppConfig.SmtpPort);

await client.AuthenticateAsync(AppConfig.SmtpUserName, AppConfig.SmtpPassword);
Expand Down
1 change: 1 addition & 0 deletions Server/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"SmtpPassword": "",
"SmtpPort": 587,
"SmtpUserName": "",
"SmtpCheckCertificateRevocation": true,
"Theme": "Dark",
"TrustedCorsOrigins": [],
"UseHsts": false,
Expand Down

0 comments on commit 1b4ba49

Please sign in to comment.