NLog.MailKit
:mailbox_with_mail: Alternative Mail target for NLog using MailKit
Install / Use
/learn @NLog/NLog.MailKitREADME
NLog.MailKit
Alternative Mail target for NLog using MailKit.
The NLog MailKit Target is able to replace the original NLog Mail Target and provides the same options.
See the NLog Wiki for available options and examples.
- Can also be combined with FallbackGroup to fallback to alternative SMTP-server on error.
- Can also be combined with BufferingWrapper to group multiple logevents into a single email.
- Can also be combined with LimitingWrapper to throttle the number of emails.
- Can also be combined with FilteringWrapper to avoid repeating identical emails.
If having trouble with output, then check NLog InternalLogger for clues. See also Troubleshooting NLog
This library is integration tested with the SmtpServer NuGet package
How to use
-
Install the package:
Install-Package NLog.MailKitor 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>());
Note that the option skipCertificateValidation="true" can prevent AuthenticationException if your remote certificate for smtpServer is invalid - not recommend!
OAuth2 Authentication
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).
This can be implemented with a Custom NLog Layout Renderer,
or by storing the details in environment variable or NLog Global Diagnostics Context (GDC)
and point SmtpUserName and SmtpPassword to these locations.
License
BSD. License of MailKit is MIT
Related Skills
node-connect
349.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
