Make login and password not required for sending email (#3764)

* Make login and password not required for sending email

close #3656

* Add space

* Remove unused "using" statements
This commit is contained in:
Umar Bolatov 2022-05-23 03:00:34 -07:00 committed by GitHub
parent 3ede0a50f0
commit d768314f03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,13 +1,8 @@
using System.ComponentModel.DataAnnotations;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
using MailKit.Net.Smtp; using MailKit.Net.Smtp;
using MimeKit; using MimeKit;
using Newtonsoft.Json;
namespace BTCPayServer.Services.Mails namespace BTCPayServer.Services.Mails
{ {
@ -15,10 +10,7 @@ namespace BTCPayServer.Services.Mails
{ {
public bool IsComplete() public bool IsComplete()
{ {
return !string.IsNullOrWhiteSpace(Server) && return !string.IsNullOrWhiteSpace(Server) && Port is int;
Port is int &&
!string.IsNullOrWhiteSpace(Login) &&
!string.IsNullOrWhiteSpace(Password);
} }
public MimeMessage CreateMailMessage(MailboxAddress to, string subject, string message, bool isHtml) public MimeMessage CreateMailMessage(MailboxAddress to, string subject, string message, bool isHtml)
@ -54,7 +46,8 @@ namespace BTCPayServer.Services.Mails
#pragma warning restore CA5359 // Do Not Disable Certificate Validation #pragma warning restore CA5359 // Do Not Disable Certificate Validation
} }
await client.ConnectAsync(Server, Port.Value, MailKit.Security.SecureSocketOptions.Auto, connectCancel.Token); await client.ConnectAsync(Server, Port.Value, MailKit.Security.SecureSocketOptions.Auto, connectCancel.Token);
await client.AuthenticateAsync(Login, Password, connectCancel.Token); if ((client.Capabilities & SmtpCapabilities.Authentication) != 0)
await client.AuthenticateAsync(Login ?? string.Empty, Password ?? string.Empty, connectCancel.Token);
} }
catch catch
{ {