Do not spam the logs about failed mail

This commit is contained in:
nicolas.dorier 2018-05-05 01:42:42 +09:00
parent 4458e63c1a
commit efdc99b9d1
3 changed files with 17 additions and 8 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);