|
35 | 35 | using System.Collections.Generic; |
36 | 36 | using System.ComponentModel; |
37 | 37 | using System.Linq; |
| 38 | +using System.Net; |
38 | 39 | using System.Text; |
39 | 40 | using MailKit.Net.Smtp; |
40 | 41 | using MailKit.Security; |
@@ -446,6 +447,19 @@ private void SendMailMessage(MimeMessage message, LogEventInfo lastEvent) |
446 | 447 | var oauth2 = new SaslMechanismOAuth2(userName, oauth2Token); |
447 | 448 | client.Authenticate(oauth2); |
448 | 449 | } |
| 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 | + } |
449 | 463 |
|
450 | 464 | client.Send(message); |
451 | 465 | InternalLogger.Trace("{0}: Sending mail done. Disconnecting", this); |
@@ -535,17 +549,12 @@ private void CheckRequiredParameters() |
535 | 549 | throw new NLogConfigurationException("MailTarget - To address is required"); |
536 | 550 | } |
537 | 551 |
|
538 | | - var smtpAuthentication = RenderLogEvent(SmtpAuthentication, LogEventInfo.CreateNullEvent()); |
539 | | - if (smtpAuthentication == SmtpAuthenticationMode.Ntlm) |
540 | | - { |
541 | | - throw new NLogConfigurationException("MailTarget - SmtpAuthentication NTLM not yet supported"); |
542 | | - } |
543 | | - |
544 | 552 | if (IsEmptyLayout(PickupDirectoryLocation) && IsEmptyLayout(SmtpServer)) |
545 | 553 | { |
546 | 554 | throw new NLogConfigurationException("MailTarget - SmtpServer is required"); |
547 | 555 | } |
548 | 556 |
|
| 557 | + var smtpAuthentication = RenderLogEvent(SmtpAuthentication, LogEventInfo.CreateNullEvent()); |
549 | 558 | if (smtpAuthentication == SmtpAuthenticationMode.OAuth2 && (IsEmptyLayout(SmtpUserName) || IsEmptyLayout(SmtpPassword))) |
550 | 559 | { |
551 | 560 | throw new NLogConfigurationException("MailTarget - SmtpUserName (OAuth UserName) and SmtpPassword (OAuth AccessToken) is required when SmtpAuthentication = OAuth2"); |
|
0 commit comments