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