Skip to content

Commit 74e28f3

Browse files
authored
NLog v6 RTM (#224)
1 parent 9ef8e80 commit 74e28f3

File tree

5 files changed

+45
-41
lines changed

5 files changed

+45
-41
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This library is integration tested with the [SmtpServer NuGet package](https://w
2626
`Install-Package NLog.MailKit` or in your csproj:
2727

2828
```xml
29-
<PackageReference Include="NLog.MailKit" Version="5.*" />
29+
<PackageReference Include="NLog.MailKit" Version="6.*" />
3030
```
3131

3232
2) Add to your nlog.config:

azure-pipelines.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,10 @@ variables:
1313
Solution: 'src/NLog.MailKit.sln'
1414
BuildPlatform: 'Any CPU'
1515
BuildConfiguration: 'Release'
16-
Version: '5.3'
16+
Version: '6.0.0'
1717
FullVersion: '$(Version).$(Build.BuildId)'
1818

1919
steps:
20-
- task: NuGetToolInstaller@0
21-
displayName: 'Use NuGet 6.x'
22-
inputs:
23-
versionSpec: 6.x
24-
2520
- task: DotNetCoreCLI@2
2621
displayName: 'dotnet restore'
2722
inputs:

src/NLog.MailKit/MailTarget.cs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,27 +114,25 @@ public MailTarget(string name) : this()
114114
/// Gets or sets sender's email address (e.g. [email protected]).
115115
/// </summary>
116116
/// <docgen category='Message Options' order='10' />
117-
[RequiredParameter]
118-
public Layout From { get; set; }
117+
public Layout From { get; set; } = Layout.Empty;
119118

120119
/// <summary>
121120
/// Gets or sets recipients' email addresses separated by semicolons (e.g. [email protected];[email protected]).
122121
/// </summary>
123122
/// <docgen category='Message Options' order='11' />
124-
[RequiredParameter]
125-
public Layout To { get; set; }
123+
public Layout To { get; set; } = Layout.Empty;
126124

127125
/// <summary>
128126
/// Gets or sets CC email addresses separated by semicolons (e.g. [email protected];[email protected]).
129127
/// </summary>
130128
/// <docgen category='Message Options' order='12' />
131-
public Layout Cc { get; set; }
129+
public Layout? Cc { get; set; }
132130

133131
/// <summary>
134132
/// Gets or sets BCC email addresses separated by semicolons (e.g. [email protected];[email protected]).
135133
/// </summary>
136134
/// <docgen category='Message Options' order='13' />
137-
public Layout Bcc { get; set; }
135+
public Layout? Bcc { get; set; }
138136

139137
/// <summary>
140138
/// Gets or sets a value indicating whether to add new lines between log entries.
@@ -147,7 +145,6 @@ public MailTarget(string name) : this()
147145
/// Gets or sets the mail subject.
148146
/// </summary>
149147
/// <docgen category='Message Options' order='5' />
150-
[RequiredParameter]
151148
public Layout Subject { get; set; } = "Message from NLog on ${machinename}";
152149

153150
/// <summary>
@@ -171,13 +168,13 @@ public Layout Body
171168
/// Gets or sets a value indicating whether to send message as HTML instead of plain text.
172169
/// </summary>
173170
/// <docgen category='Message Options' order='11' />
174-
public Layout<bool> Html { get; set; }
171+
public Layout<bool> Html { get; set; } = false;
175172

176173
/// <summary>
177174
/// Gets or sets SMTP Server to be used for sending.
178175
/// </summary>
179176
/// <docgen category='SMTP Options' order='10' />
180-
public Layout SmtpServer { get; set; }
177+
public Layout SmtpServer { get; set; } = Layout.Empty;
181178

182179
/// <summary>
183180
/// Gets or sets SMTP Authentication mode.
@@ -189,21 +186,21 @@ public Layout Body
189186
/// Gets or sets the username used to connect to SMTP server (used when <see cref="SmtpAuthentication"/> is set to "basic").
190187
/// </summary>
191188
/// <docgen category='SMTP Options' order='12' />
192-
public Layout SmtpUserName { get; set; }
189+
public Layout? SmtpUserName { get; set; }
193190

194191
/// <summary>
195192
/// Gets or sets the password used to authenticate against SMTP server (used when <see cref="SmtpAuthentication"/> is set to "basic").
196193
/// </summary>
197194
/// <docgen category='SMTP Options' order='13' />
198-
public Layout SmtpPassword { get; set; }
195+
public Layout? SmtpPassword { get; set; }
199196

200197
/// <summary>
201198
/// Gets or sets a value indicating whether SSL (secure sockets layer) should be used when communicating with SMTP server.
202199
///
203200
/// See also <see cref="SecureSocketOption" />
204201
/// </summary>
205202
/// <docgen category='SMTP Options' order='14' />.
206-
public Layout<bool> EnableSsl { get; set; }
203+
public Layout<bool> EnableSsl { get; set; } = false;
207204

208205
/// <summary>
209206
/// Get or set whether the client should use the REQUIRETLS extension if it is available.
@@ -216,7 +213,7 @@ public Layout Body
216213
/// <note type="note">This feature is only available if connected SMTP server supports capability
217214
/// <see cref="SmtpCapabilities.RequireTLS"/> flag when sending the message.</note>
218215
/// </remarks>
219-
public Layout<bool> RequireTLS { get; set; }
216+
public Layout<bool> RequireTLS { get; set; } = false;
220217

221218
/// <summary>
222219
/// Provides a way of specifying the SSL and/or TLS encryption
@@ -237,19 +234,19 @@ public Layout Body
237234
/// Gets or sets a value indicating whether SmtpClient should ignore invalid certificate.
238235
/// </summary>
239236
/// <docgen category='SMTP Options' order='16' />
240-
public Layout<bool> SkipCertificateValidation { get; set; }
237+
public Layout<bool> SkipCertificateValidation { get; set; } = false;
241238

242239
/// <summary>
243240
/// Gets or sets the priority used for sending mails.
244241
/// </summary>
245242
/// <docgen category='Message Options' order='100' />
246-
public Layout Priority { get; set; }
243+
public Layout Priority { get; set; } = Layout.Empty;
247244

248245
/// <summary>
249246
/// Gets or sets a value indicating whether NewLine characters in the body should be replaced with <br/> tags.
250247
/// </summary>
251248
/// <remarks>Only happens when <see cref="Html"/> is set to true.</remarks>
252-
public Layout<bool> ReplaceNewlineWithBrTagInHtml { get; set; }
249+
public Layout<bool> ReplaceNewlineWithBrTagInHtml { get; set; } = false;
253250

254251
/// <summary>
255252
/// Gets or sets a value indicating the SMTP client timeout (in milliseconds)
@@ -261,7 +258,7 @@ public Layout Body
261258
/// Gets or sets the folder where applications save mail messages to be processed by the local SMTP server.
262259
/// </summary>
263260
/// <docgen category='SMTP Options' order='17' />
264-
public Layout PickupDirectoryLocation { get; set; }
261+
public Layout? PickupDirectoryLocation { get; set; }
265262

266263
/// <summary>
267264
/// Gets the array of email headers that are transmitted with this email message
@@ -483,15 +480,25 @@ internal string ResolvePickupDirectoryLocationFilePath(string pickupDirectoryLoc
483480

484481
private void CheckRequiredParameters()
485482
{
483+
if (From is null || ReferenceEquals(From, Layout.Empty))
484+
{
485+
throw new NLogConfigurationException("MailTarget - From address is required");
486+
}
487+
488+
if (To is null || ReferenceEquals(To, Layout.Empty))
489+
{
490+
throw new NLogConfigurationException("MailTarget - To address is required");
491+
}
492+
486493
var smtpAuthentication = RenderLogEvent(SmtpAuthentication, LogEventInfo.CreateNullEvent());
487494
if (smtpAuthentication == SmtpAuthenticationMode.Ntlm)
488495
{
489-
throw new NLogConfigurationException("SmtpAuthentication NTLM not yet supported");
496+
throw new NLogConfigurationException("MailTarget - SmtpAuthentication NTLM not yet supported");
490497
}
491498

492-
if (PickupDirectoryLocation is null && SmtpServer is null)
499+
if ((PickupDirectoryLocation is null || ReferenceEquals(PickupDirectoryLocation, Layout.Empty)) && (SmtpServer is null || ReferenceEquals(SmtpServer, Layout.Empty)))
493500
{
494-
throw new NLogConfigurationException("SmtpServer is required");
501+
throw new NLogConfigurationException("MailTarget - SmtpServer is required");
495502
}
496503
}
497504

@@ -622,7 +629,7 @@ internal static MessagePriority ParseMessagePriority(string priority)
622629
/// <param name="layout">layout with addresses, ; separated</param>
623630
/// <param name="logEvent">event for rendering the <paramref name="layout" /></param>
624631
/// <returns>added a address?</returns>
625-
private bool AddAddresses(InternetAddressList mailAddressCollection, Layout layout, LogEventInfo logEvent)
632+
private bool AddAddresses(InternetAddressList mailAddressCollection, Layout? layout, LogEventInfo logEvent)
626633
{
627634
var added = false;
628635
var mailAddresses = RenderLogEvent(layout, logEvent);

src/NLog.MailKit/NLog.MailKit.csproj

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,29 @@ If the mail target was already available on your platform, this package will ove
2828
<AssemblyOriginatorKeyFile>NLog.snk</AssemblyOriginatorKeyFile>
2929
<DelaySign>false</DelaySign>
3030
<PackageReleaseNotes>
31-
- Updated to MailKit v4.7.1.1 (Fix security issue)
32-
- Added option RequireTLS
31+
- Updated NLog v6
32+
- Enable Nullable API
3333

3434
See https://github.com/NLog/NLog.MailKit/releases
3535

3636
</PackageReleaseNotes>
37-
<AssemblyVersion>5.0.0.0</AssemblyVersion>
37+
<AssemblyVersion>6.0.0.0</AssemblyVersion>
3838
<PackageReadmeFile>README.md</PackageReadmeFile>
39-
<!--AssemblyVersion: keep 5.0.0.0-->
40-
</PropertyGroup>
41-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
42-
<DocumentationFile>bin\Release\$(TargetFramework)\NLog.MailKit.xml</DocumentationFile>
43-
<OutputPath>bin\Release\</OutputPath>
44-
<DefineConstants>RELEASE</DefineConstants>
39+
40+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
41+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
42+
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
43+
<IsTrimmable Condition=" '$(TargetFramework)' == 'netstandard2.1' ">true</IsTrimmable>
44+
<IsAotCompatible Condition=" '$(TargetFramework)' == 'netstandard2.1' ">true</IsAotCompatible>
45+
<Nullable>enable</Nullable>
46+
<LangVersion>9.0</LangVersion>
4547
</PropertyGroup>
4648
<ItemGroup>
4749
<PackageReference Include="MailKit" Version="4.7.1.1" />
4850
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
4951
</ItemGroup>
5052
<ItemGroup>
51-
<PackageReference Include="NLog" Version="5.2.2" />
53+
<PackageReference Include="NLog" Version="6.0.1" />
5254
</ItemGroup>
5355
<ItemGroup>
5456
<None Include="..\..\README.md">

test/NLog.MailKit.Tests/NLog.MailKit.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
66
<SignAssembly>true</SignAssembly>
77
<AssemblyOriginatorKeyFile>NLog.snk</AssemblyOriginatorKeyFile>
88
<DelaySign>false</DelaySign>
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
1313
<PackageReference Include="SmtpServer" Version="7.2.0" />
1414
<PackageReference Include="xunit" Version="2.9.2" />
1515
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">

0 commit comments

Comments
 (0)