Skip to content

Commit acb8331

Browse files
committed
Support SmtpAuthenticationMode.Ntlm
1 parent 549c04b commit acb8331

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/NLog.MailKit/MailTarget.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
using System.Collections.Generic;
3636
using System.ComponentModel;
3737
using System.Linq;
38+
using System.Net;
3839
using System.Text;
3940
using MailKit.Net.Smtp;
4041
using MailKit.Security;
@@ -446,6 +447,19 @@ private void SendMailMessage(MimeMessage message, LogEventInfo lastEvent)
446447
var oauth2 = new SaslMechanismOAuth2(userName, oauth2Token);
447448
client.Authenticate(oauth2);
448449
}
450+
else if (smtpAuthentication == SmtpAuthenticationMode.Ntlm)
451+
{
452+
var userName = RenderLogEvent(SmtpUserName, lastEvent);
453+
var password = RenderLogEvent(SmtpPassword, lastEvent);
454+
if (!string.IsNullOrWhiteSpace(userName))
455+
{
456+
client.Authenticate(new SaslMechanismNtlm(userName, password));
457+
}
458+
else
459+
{
460+
client.Authenticate(new SaslMechanismNtlm(CredentialCache.DefaultNetworkCredentials));
461+
}
462+
}
449463

450464
client.Send(message);
451465
InternalLogger.Trace("{0}: Sending mail done. Disconnecting", this);

0 commit comments

Comments
 (0)