Skip to content

Commit ceca2c0

Browse files
authored
Updated dependencies and add support for RequireTLS (#222)
1 parent 05270d6 commit ceca2c0

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

azure-pipelines.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ variables:
1313
Solution: 'src/NLog.MailKit.sln'
1414
BuildPlatform: 'Any CPU'
1515
BuildConfiguration: 'Release'
16-
Version: '5.2.0'
16+
Version: '5.2.1'
1717
FullVersion: '$(Version).$(Build.BuildId)'
1818

1919
steps:
@@ -29,7 +29,7 @@ steps:
2929
projects: '$(Solution)'
3030
verbosityRestore: Minimal
3131

32-
- task: SonarCloudPrepare@2
32+
- task: SonarCloudPrepare@3
3333
displayName: 'Prepare SonarCloud analysis'
3434
inputs:
3535
SonarCloud: 'Sonarcloud'
@@ -60,10 +60,10 @@ steps:
6060
configuration: '$(BuildConfiguration)'
6161
rerunFailedTests: true
6262

63-
- task: SonarCloudAnalyze@2
63+
- task: SonarCloudAnalyze@3
6464
displayName: 'Run SonarCloud Analysis'
6565

66-
- task: SonarCloudPublish@2
66+
- task: SonarCloudPublish@3
6767
displayName: 'Publish SonarCloud Quality Gate'
6868

6969
- task: CopyFiles@2

src/NLog.MailKit/MailTarget.cs

+21-1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,19 @@ public Layout Body
205205
/// <docgen category='SMTP Options' order='14' />.
206206
public Layout<bool> EnableSsl { get; set; }
207207

208+
/// <summary>
209+
/// Get or set whether the client should use the REQUIRETLS extension if it is available.
210+
/// </summary>
211+
/// <remarks>
212+
/// <para>Gets or sets whether the client should use the REQUIRETLS extension if it is available.</para>
213+
/// <para>The REQUIRETLS extension (as defined in rfc8689) is a way to ensure that every SMTP server
214+
/// that a message passes through on its way to the recipient is required to use a TLS connection in
215+
/// order to transfer the message to the next SMTP server.</para>
216+
/// <note type="note">This feature is only available if connected SMTP server supports capability
217+
/// <see cref="SmtpCapabilities.RequireTLS"/> flag when sending the message.</note>
218+
/// </remarks>
219+
public Layout<bool> RequireTLS { get; set; }
220+
208221
/// <summary>
209222
/// Provides a way of specifying the SSL and/or TLS encryption
210223
///
@@ -354,6 +367,8 @@ private void SendMailMessage(MimeMessage message, LogEventInfo lastEvent)
354367
}
355368

356369
var enableSsl = RenderLogEvent(EnableSsl, lastEvent);
370+
var requireTLS = RenderLogEvent(RequireTLS, lastEvent);
371+
357372
var secureSocketOptions = enableSsl ? SecureSocketOptions.SslOnConnect : RenderLogEvent(SecureSocketOption, lastEvent, DefaultSecureSocketOption);
358373
var smtpPort = RenderLogEvent(SmtpPort, lastEvent);
359374
InternalLogger.Debug("Sending mail to {0} using {1}:{2}", message.To, renderedHost, smtpPort);
@@ -366,8 +381,13 @@ private void SendMailMessage(MimeMessage message, LogEventInfo lastEvent)
366381
client.ServerCertificateValidationCallback += (s, cert, chain, sslPolicyErrors) => true;
367382
}
368383

384+
if (requireTLS)
385+
{
386+
client.RequireTLS = true; // Requires SMTP Server capability SmtpCapabilities.RequireTLS
387+
}
388+
369389
client.Connect(renderedHost, smtpPort, secureSocketOptions);
370-
InternalLogger.Trace("{0}: Connecting succesfull", this);
390+
InternalLogger.Trace("{0}: Connecting succesfull with SmtpCapabilities={1}", this, client.Capabilities);
371391

372392
// Note: since we don't have an OAuth2 token, disable
373393
// the XOAUTH2 authentication mechanism.

src/NLog.MailKit/NLog.MailKit.csproj

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
3+
<TargetFrameworks>net462;netstandard2.0;netstandard2.1</TargetFrameworks>
44
<Authors>Julian Verdurmen</Authors>
55
<Company>NLog</Company>
66
<Description>NLog Mail Target for .NET Core &amp; .NET Standard 2.0+ using MailKit.
@@ -28,11 +28,8 @@ 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-
- Added support for PickupDirectoryLocation
32-
- Added support for email headers
33-
- Added target-alias mailkit
34-
- Updated to NLog v5.2.2
35-
- Updated to MailKit v3.3.0
31+
- Updated to MailKit v4.7.1.1 (Fix security issue)
32+
- Added option RequireTLS
3633

3734
See https://github.com/NLog/NLog.MailKit/releases
3835

@@ -47,7 +44,7 @@ See https://github.com/NLog/NLog.MailKit/releases
4744
<DefineConstants>RELEASE</DefineConstants>
4845
</PropertyGroup>
4946
<ItemGroup>
50-
<PackageReference Include="MailKit" Version="3.3.0" />
47+
<PackageReference Include="MailKit" Version="4.7.1.1" />
5148
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
5249
</ItemGroup>
5350
<ItemGroup>

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
1313
<PackageReference Include="SmtpServer" Version="7.2.0" />
14-
<PackageReference Include="xunit" Version="2.8.0" />
15-
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
14+
<PackageReference Include="xunit" Version="2.9.2" />
15+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
1616
<PrivateAssets>all</PrivateAssets>
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1818
</PackageReference>

0 commit comments

Comments
 (0)