From ce9067a434223a96943eca9df952a63249880b60 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 5 Oct 2017 08:34:46 -0400 Subject: [PATCH] SMTP config allow no username/password --- src/Core/GlobalSettings.cs | 1 + .../Implementations/SmtpMailDeliveryService.cs | 11 ++++++++--- src/Core/Utilities/ServiceCollectionExtensions.cs | 4 +--- util/Setup/Program.cs | 1 + 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Core/GlobalSettings.cs b/src/Core/GlobalSettings.cs index f6d1b39d5..a9b7740bc 100644 --- a/src/Core/GlobalSettings.cs +++ b/src/Core/GlobalSettings.cs @@ -92,6 +92,7 @@ namespace Bit.Core public bool Ssl { get; set; } = false; public string Username { get; set; } public string Password { get; set; } + public bool UseDefaultCredentials { get; set; } = false; } } diff --git a/src/Core/Services/Implementations/SmtpMailDeliveryService.cs b/src/Core/Services/Implementations/SmtpMailDeliveryService.cs index 80b654952..1df678372 100644 --- a/src/Core/Services/Implementations/SmtpMailDeliveryService.cs +++ b/src/Core/Services/Implementations/SmtpMailDeliveryService.cs @@ -23,11 +23,16 @@ namespace Bit.Core.Services public Task SendEmailAsync(Models.Mail.MailMessage message) { var client = new SmtpClient(_globalSettings.Mail.Smtp.Host, _globalSettings.Mail.Smtp.Port); - client.UseDefaultCredentials = false; client.EnableSsl = _globalSettings.Mail.Smtp.Ssl; + client.UseDefaultCredentials = _globalSettings.Mail.Smtp.UseDefaultCredentials; client.DeliveryMethod = SmtpDeliveryMethod.Network; - client.Credentials = new NetworkCredential(_globalSettings.Mail.Smtp.Username, - _globalSettings.Mail.Smtp.Password); + + if(!string.IsNullOrWhiteSpace(_globalSettings.Mail.Smtp.Username) && + !string.IsNullOrWhiteSpace(_globalSettings.Mail.Smtp.Password)) + { + client.Credentials = new NetworkCredential(_globalSettings.Mail.Smtp.Username, + _globalSettings.Mail.Smtp.Password); + } var smtpMessage = new MailMessage(); smtpMessage.From = new MailAddress(_globalSettings.Mail.ReplyToEmail, _globalSettings.SiteName); diff --git a/src/Core/Utilities/ServiceCollectionExtensions.cs b/src/Core/Utilities/ServiceCollectionExtensions.cs index 97e5937e8..bcb34f567 100644 --- a/src/Core/Utilities/ServiceCollectionExtensions.cs +++ b/src/Core/Utilities/ServiceCollectionExtensions.cs @@ -71,9 +71,7 @@ namespace Bit.Core.Utilities { services.AddSingleton(); } - else if(CoreHelpers.SettingHasValue(globalSettings.Mail?.Smtp?.Host) && - CoreHelpers.SettingHasValue(globalSettings.Mail?.Smtp?.Username) && - CoreHelpers.SettingHasValue(globalSettings.Mail?.Smtp?.Password)) + else if(CoreHelpers.SettingHasValue(globalSettings.Mail?.Smtp?.Host)) { services.AddSingleton(); } diff --git a/util/Setup/Program.cs b/util/Setup/Program.cs index 9b5eb1969..684fc5b4a 100644 --- a/util/Setup/Program.cs +++ b/util/Setup/Program.cs @@ -403,6 +403,7 @@ globalSettings__mail__smtp__username=REPLACE globalSettings__mail__smtp__password=REPLACE globalSettings__mail__smtp__ssl=true globalSettings__mail__smtp__port=587 +globalSettings__mail__smtp__useDefaultCredentials=false globalSettings__disableUserRegistration=false"); if(!_push)