You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14-6Lines changed: 14 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,15 +10,11 @@
10
10
Alternative Mail target for [NLog](https://github.com/nlog/nlog) using [MailKit](https://github.com/jstedfast/MailKit). Compatible with .NET standard 2+
11
11
12
12
Including this package will replace the original mail target and has the
13
-
same options as the original mail target, see [docs of the original mailTarget](https://github.com/NLog/NLog/wiki/Mail-Target)
14
-
15
-
Currently not implemented:
16
-
17
-
- NTLM auth
13
+
same options as the original mail target, see [docs of the original mailTarget](https://github.com/NLog/NLog/wiki/Mail-Target).
14
+
But Mailkit does not yet support `SmtpAuthentication = NTLM`.
18
15
19
16
This library is integration tested with the [SmtpServer NuGet package](https://www.nuget.org/packages/SmtpServer/)
20
17
21
-
22
18
### How to use
23
19
24
20
1) Install the package:
@@ -47,6 +43,18 @@ See the [NLog Wiki](https://github.com/NLog/NLog/wiki/Mail-Target) for available
47
43
48
44
Note that the option `skipCertificateValidation="true"` can prevent `AuthenticationException` if your remote certificate for smtpServer is invalid - not recommend!
49
45
46
+
### OAuth2 Authentication
47
+
48
+
Mailkit supports `OAuth2` authentication by specifying `SmtpAuthentication = OAuth2` together with:
49
+
- `SmtpUserName = ${gdc:OAuthClientId}`
50
+
- `SmtpPassword = ${gdc:OAuthClientSecret}`
51
+
52
+
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)](https://github.com/NLog/NLog/wiki/Gdc-layout-renderer) with the key `OAuthClientSecret` (And ensure it is refreshed before expiry).
53
+
Alternative store the access token in an environment variable and use the NLog [${environment:variable=OAuthClientSecret}](https://github.com/NLog/NLog/wiki/Environment-layout-renderer) instead of NLog GDC.
54
+
55
+
- [Using OAuth2 With Microsoft Outlook Exchange](https://github.com/jstedfast/MailKit/blob/master/ExchangeOAuth2.md)
56
+
- [Using OAuth2 With Google GMail](https://github.com/jstedfast/MailKit/blob/master/GMailOAuth2.md)
thrownewNLogConfigurationException("MailTarget - SmtpUserName (OAuth UserName) and SmtpPassword (OAuth AccessToken) is required when SmtpAuthentication = OAuth2");
0 commit comments