mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Do not spam the logs about failed mail
This commit is contained in:
@@ -243,10 +243,7 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(string.IsNullOrWhiteSpace(model.Settings.From)
|
if(!model.Settings.IsComplete())
|
||||||
|| string.IsNullOrWhiteSpace(model.TestEmail)
|
|
||||||
|| string.IsNullOrWhiteSpace(model.Settings.Login)
|
|
||||||
|| string.IsNullOrWhiteSpace(model.Settings.Server))
|
|
||||||
{
|
{
|
||||||
model.StatusMessage = "Error: Required fields missing";
|
model.StatusMessage = "Error: Required fields missing";
|
||||||
return View(model);
|
return View(model);
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ namespace BTCPayServer.Services.Mails
|
|||||||
}
|
}
|
||||||
public async Task SendEmailAsync(string email, string subject, string message)
|
public async Task SendEmailAsync(string email, string subject, string message)
|
||||||
{
|
{
|
||||||
var settings = await _Repository.GetSettingAsync<EmailSettings>();
|
var settings = await _Repository.GetSettingAsync<EmailSettings>() ?? new EmailSettings();
|
||||||
if (settings == null)
|
if (!settings.IsComplete())
|
||||||
{
|
{
|
||||||
Logs.Configuration.LogWarning("Should have sent email, but email settings are not configured");
|
Logs.Configuration.LogWarning("Should have sent email, but email settings are not configured");
|
||||||
return;
|
return;
|
||||||
@@ -36,8 +36,8 @@ namespace BTCPayServer.Services.Mails
|
|||||||
|
|
||||||
public async Task SendMailCore(string email, string subject, string message)
|
public async Task SendMailCore(string email, string subject, string message)
|
||||||
{
|
{
|
||||||
var settings = await _Repository.GetSettingAsync<EmailSettings>();
|
var settings = await _Repository.GetSettingAsync<EmailSettings>() ?? new EmailSettings();
|
||||||
if (settings == null)
|
if (!settings.IsComplete())
|
||||||
throw new InvalidOperationException("Email settings not configured");
|
throw new InvalidOperationException("Email settings not configured");
|
||||||
var smtp = settings.CreateSmtpClient();
|
var smtp = settings.CreateSmtpClient();
|
||||||
MailMessage mail = new MailMessage(settings.From, email, subject, message);
|
MailMessage mail = new MailMessage(settings.From, email, subject, message);
|
||||||
|
|||||||
@@ -40,6 +40,18 @@ namespace BTCPayServer.Services.Mails
|
|||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsComplete()
|
||||||
|
{
|
||||||
|
SmtpClient smtp = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
smtp = CreateSmtpClient();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public SmtpClient CreateSmtpClient()
|
public SmtpClient CreateSmtpClient()
|
||||||
{
|
{
|
||||||
SmtpClient client = new SmtpClient(Server, Port.Value);
|
SmtpClient client = new SmtpClient(Server, Port.Value);
|
||||||
|
|||||||
Reference in New Issue
Block a user