diff --git a/src/Core/Services/Implementations/SmtpMailDeliveryService.cs b/src/Core/Services/Implementations/SmtpMailDeliveryService.cs index c63c795388..80b6549524 100644 --- a/src/Core/Services/Implementations/SmtpMailDeliveryService.cs +++ b/src/Core/Services/Implementations/SmtpMailDeliveryService.cs @@ -22,46 +22,45 @@ namespace Bit.Core.Services public Task SendEmailAsync(Models.Mail.MailMessage message) { - using(var client = new SmtpClient(_globalSettings.Mail.Smtp.Host, _globalSettings.Mail.Smtp.Port)) + var client = new SmtpClient(_globalSettings.Mail.Smtp.Host, _globalSettings.Mail.Smtp.Port); + client.UseDefaultCredentials = false; + client.EnableSsl = _globalSettings.Mail.Smtp.Ssl; + client.DeliveryMethod = SmtpDeliveryMethod.Network; + 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); + smtpMessage.Subject = message.Subject; + smtpMessage.SubjectEncoding = Encoding.UTF8; + smtpMessage.BodyEncoding = Encoding.UTF8; + smtpMessage.BodyTransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable; + foreach(var address in message.ToEmails) { - client.UseDefaultCredentials = false; - client.EnableSsl = _globalSettings.Mail.Smtp.Ssl; - client.DeliveryMethod = SmtpDeliveryMethod.Network; - 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); - smtpMessage.Subject = message.Subject; - smtpMessage.SubjectEncoding = Encoding.UTF8; - smtpMessage.BodyEncoding = Encoding.UTF8; - smtpMessage.BodyTransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable; - foreach(var address in message.ToEmails) - { - smtpMessage.To.Add(new MailAddress(address)); - } - - if(string.IsNullOrWhiteSpace(message.TextContent)) - { - smtpMessage.IsBodyHtml = true; - smtpMessage.Body = message.HtmlContent; - } - else - { - smtpMessage.Body = message.TextContent; - var htmlView = AlternateView.CreateAlternateViewFromString(message.HtmlContent); - htmlView.ContentType = new System.Net.Mime.ContentType("text/html"); - smtpMessage.AlternateViews.Add(htmlView); - } - - client.SendCompleted += (s, e) => - { - smtpMessage.Dispose(); - }; - - client.SendAsync(smtpMessage, null); - return Task.FromResult(0); + smtpMessage.To.Add(new MailAddress(address)); } + + if(string.IsNullOrWhiteSpace(message.TextContent)) + { + smtpMessage.IsBodyHtml = true; + smtpMessage.Body = message.HtmlContent; + } + else + { + smtpMessage.Body = message.TextContent; + var htmlView = AlternateView.CreateAlternateViewFromString(message.HtmlContent); + htmlView.ContentType = new System.Net.Mime.ContentType("text/html"); + smtpMessage.AlternateViews.Add(htmlView); + } + + client.SendCompleted += (s, e) => + { + smtpMessage.Dispose(); + client.Dispose(); + }; + + client.SendAsync(smtpMessage, null); + return Task.FromResult(0); } } } diff --git a/util/Setup/Program.cs b/util/Setup/Program.cs index 835776d747..79425596ec 100644 --- a/util/Setup/Program.cs +++ b/util/Setup/Program.cs @@ -397,7 +397,7 @@ globalSettings__mail__smtp__host=REPLACE globalSettings__mail__smtp__username=REPLACE globalSettings__mail__smtp__password=REPLACE globalSettings__mail__smtp__ssl=true -globalSettings__mail__smtp__port=465"); +globalSettings__mail__smtp__port=587"); if(!_push) {