NLog Mail Target for sending email using .NET SmtpClient for each logevent.
- Combine with FallbackGroup to fallback to alternative SMTP-server on error.
- Combine with BufferingWrapper and AutoFlushWrapper to group multiple logevents into a single email.
- Combine with LimitingWrapper to throttle the number of emails.
- Combine with FilteringWrapper to avoid repeating identical emails.
If having trouble with output, then check NLog InternalLogger for clues. See also Troubleshooting NLog
See the NLog Wiki for available options and examples.
Note there is also an alternative NLog.MailKit-nuget-package that depends on the MailKit-library.
⚠️ Microsoft recommends not to use the SmtpClient class for new development because SmtpClient doesn't support many modern protocols. Use MailKit or other libraries instead. For more information, see SmtpClient shouldn't be used.
NLog will only recognize type-alias Mail when loading from NLog.config-file, if having added extension to NLog.config-file:
<extensions>
<add assembly="NLog.Targets.Mail"/>
</extensions>Alternative register from code using fluent configuration API:
LogManager.Setup().SetupExtensions(ext => {
ext.RegisterTarget<NLog.Targets.MailTarget>();
});