NLog Mail Target for .NET Core & .NET Standard 2.0+ using MailKit. This package add the mail target to NLog and has the same options* as the original Mail Target. If the mail target was already available on your platform, this package will overwrite the original Mail Target. * Compared to the original MailTarget, the following options aren't implemented: - NTLM auth * MailKit gives more control of the sockets, so you get the `secureSocketOption` option for free!
Including this package will replace the original mail target and has the
same options as the original mail target, see docs of the original mailTarget.
But Mailkit does not yet support SmtpAuthentication = NTLM.
This library is integration tested with the SmtpServer NuGet package
Install the package:
Install-Package NLog.MailKit or in your csproj:
<PackageReference Include="NLog.MailKit" Version="6.*" />
Add to your nlog.config:
<extensions>
<add assembly="NLog.MailKit"/>
</extensions>
Alternative register from code using fluent configuration API:
LogManager.Setup().SetupExtensions(ext => ext.RegisterTarget<NLog.MailKit.MailTarget>());
See the NLog Wiki for available options and examples.
Note that the option skipCertificateValidation="true" can prevent AuthenticationException if your remote certificate for smtpServer is invalid - not recommend!
Mailkit supports OAuth2 authentication by specifying SmtpAuthentication = OAuth2 together with:
SmtpUserName = ${gdc:OAuthClientId}SmtpPassword = ${gdc:OAuthClientSecret}Before using OAuth2 authentication, make sure to acquire an access token from your email provider (e.g., Gmail, Outlook) and store it in the Global Diagnostics Context (GDC) with the key OAuthClientSecret (And ensure it is refreshed before expiry).
Alternative store the access token in an environment variable and use the NLog ${environment:variable=OAuthClientSecret} instead of NLog GDC.
BSD. License of MailKit is MIT