diff --git a/.gitignore b/.gitignore index 878a3d2..37f6d89 100644 --- a/.gitignore +++ b/.gitignore @@ -183,3 +183,5 @@ UpgradeLog*.htm # Microsoft Fakes FakesAssemblies/ /.vs + +.dotnetcli diff --git a/CHANGES.md b/CHANGES.md index f2cf657..f2229f5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,6 @@ +2.5.0 +* remove MailKit and support for net4.5, net 4.8, netstandard1.3, netstandard2.1 + 2.2.2 * allow disabling SMTP SSL certification validation diff --git a/README.md b/README.md index 08778b1..7e3fad0 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Sends log events by SMTP email. **Package** - [Serilog.Sinks.Email](http://nuget.org/packages/serilog.sinks.email) -| **Platforms** - .NET 4.5 + ```csharp var log = new LoggerConfiguration() diff --git a/appveyor.yml b/appveyor.yml index 634cc5a..f356483 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ version: '{build}' skip_tags: true image: -- Visual Studio 2019 +- Visual Studio 2022 - Ubuntu configuration: Release test: off diff --git a/build.sh b/build.sh index 8fb8b37..ed05ae2 100644 --- a/build.sh +++ b/build.sh @@ -10,14 +10,11 @@ dotnet restore echo "🤖 Attempting to build..." for path in src/**/*.csproj; do - dotnet build -f netstandard1.3 -c Release ${path} dotnet build -f netstandard2.0 -c Release ${path} - dotnet build -f netstandard2.1 -c Release ${path} done echo "🤖 Running tests..." for path in test/*.Tests/*.csproj; do - dotnet test -f netcoreapp2.2 -c Release ${path} - dotnet test -f netcoreapp3.1 -c Release ${path} + dotnet test -f net6.0 -c Release ${path} done diff --git a/global.json b/global.json index e3bbb00..8da8696 100644 --- a/global.json +++ b/global.json @@ -1,7 +1,7 @@ { "sdk": { "allowPrerelease": false, - "version": "3.1.100", + "version": "7.0.201", "rollForward": "latestFeature" } } diff --git a/src/Serilog.Sinks.Email/Serilog.Sinks.Email.csproj b/src/Serilog.Sinks.Email/Serilog.Sinks.Email.csproj index 00d3be7..b340bdf 100644 --- a/src/Serilog.Sinks.Email/Serilog.Sinks.Email.csproj +++ b/src/Serilog.Sinks.Email/Serilog.Sinks.Email.csproj @@ -1,10 +1,10 @@ - + The email sink for Serilog - 2.4.1 + 2.5.0 Serilog Contributors - net45;net47;netstandard1.3;netstandard2.0;netstandard2.1 + netstandard2.0 true Serilog.Sinks.Email Serilog @@ -26,55 +26,14 @@ - - - - - - - - - - - - - - - - - $(DefineConstants);SYSTEM_NET - - - $(DefineConstants);SYSTEM_NET - - - - $(DefineConstants);MAIL_KIT - - - $(DefineConstants);MAIL_KIT - - - $(DefineConstants);MAIL_KIT - + + - - - - - - - - - - - - - + True diff --git a/src/Serilog.Sinks.Email/Sinks/Email/EmailConnectionInfo.cs b/src/Serilog.Sinks.Email/Sinks/Email/EmailConnectionInfo.cs index 1bdd699..9058bcb 100644 --- a/src/Serilog.Sinks.Email/Sinks/Email/EmailConnectionInfo.cs +++ b/src/Serilog.Sinks.Email/Sinks/Email/EmailConnectionInfo.cs @@ -96,22 +96,9 @@ public EmailConnectionInfo() /// public bool IsBodyHtml { get; set; } -#if MAIL_KIT - /// - /// Set secure socket option - /// - public SecureSocketOptions? SecureSocketOption { get; set; } - -#endif - internal virtual IEmailTransport CreateEmailTransport() { -#if SYSTEM_NET return new SystemMailEmailTransport(this); -#endif -#if MAIL_KIT - return new MailKitEmailTransport(this); -#endif } } } diff --git a/src/Serilog.Sinks.Email/Sinks/Email/MailKitEmailTransport.cs b/src/Serilog.Sinks.Email/Sinks/Email/MailKitEmailTransport.cs deleted file mode 100644 index 7e88687..0000000 --- a/src/Serilog.Sinks.Email/Sinks/Email/MailKitEmailTransport.cs +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2014 Serilog Contributors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if MAIL_KIT - -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using MailKit.Net.Smtp; -using MimeKit; - -namespace Serilog.Sinks.Email -{ - class MailKitEmailTransport: IEmailTransport - { - readonly EmailConnectionInfo _connectionInfo; - - public MailKitEmailTransport(EmailConnectionInfo connectionInfo) - { - _connectionInfo = connectionInfo; - } - - public async Task SendMailAsync(EmailMessage emailMessage) - { - var fromAddress = MailboxAddress.Parse(emailMessage.From); - var mimeMessage = new MimeMessage(); - mimeMessage.From.Add(fromAddress); - mimeMessage.To.AddRange(emailMessage.To.Select(MailboxAddress.Parse)); - mimeMessage.Subject = emailMessage.Subject; - mimeMessage.Body = _connectionInfo.IsBodyHtml - ? new BodyBuilder { HtmlBody = emailMessage.Body }.ToMessageBody() - : new BodyBuilder { TextBody = emailMessage.Body }.ToMessageBody(); - using (var smtpClient = OpenConnectedSmtpClient()) - { - await smtpClient.SendAsync(mimeMessage); - await smtpClient.DisconnectAsync(quit: true); - } - } - SmtpClient OpenConnectedSmtpClient() - { - var smtpClient = new SmtpClient(); - if (!string.IsNullOrWhiteSpace(_connectionInfo.MailServer)) - { - if (_connectionInfo.ServerCertificateValidationCallback != null) - { - smtpClient.ServerCertificateValidationCallback += _connectionInfo.ServerCertificateValidationCallback; - } - - smtpClient.Connect( - _connectionInfo.MailServer, _connectionInfo.Port, - useSsl: _connectionInfo.EnableSsl); - - if (_connectionInfo.NetworkCredentials != null) - { - smtpClient.Authenticate( - Encoding.UTF8, - _connectionInfo.NetworkCredentials.GetCredential( - _connectionInfo.MailServer, _connectionInfo.Port, "smtp")); - } - } - return smtpClient; - } - - public void Dispose() - { - } - } -} -#endif diff --git a/src/Serilog.Sinks.Email/Sinks/Email/SecureSocketOptions.cs b/src/Serilog.Sinks.Email/Sinks/Email/SecureSocketOptions.cs deleted file mode 100644 index 37551cb..0000000 --- a/src/Serilog.Sinks.Email/Sinks/Email/SecureSocketOptions.cs +++ /dev/null @@ -1,69 +0,0 @@ -// -// SecureSocketOptions.cs -// -// Author: Jeffrey Stedfast -// -// Copyright (c) 2013-2021 .NET Foundation and Contributors -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#if MAIL_KIT - -namespace Serilog.Sinks.Email -{ - /// Secure socket options. - /// - /// Provides a way of specifying the SSL and/or TLS encryption that - /// should be used for a connection. - /// - public enum SecureSocketOptions - { - /// - /// No SSL or TLS encryption should be used. - /// - None = 0, - - /// - /// Allow the implementation to decide which SSL or TLS options to use (default). - /// If the server does not support SSL or TLS, then the connection will continue - /// without any encryption. - /// - Auto = 1, - - /// - /// The connection should use SSL or TLS encryption immediately. - /// - SslOnConnect = 2, - - /// - /// Elevates the connection to use TLS encryption immediately after reading the greeting - /// and capabilities of the server. - /// - StartTls = 3, - - /// - /// Elevates the connection to use TLS encryption immediately after reading the greeting - /// and capabilities of the server, but only if the server supports the STARTTLS - /// extension. - /// - StartTlsWhenAvailable = 4 - } -} - -#endif diff --git a/src/Serilog.Sinks.Email/Sinks/Email/SystemMailEmailTransport.cs b/src/Serilog.Sinks.Email/Sinks/Email/SystemMailEmailTransport.cs index 58484ae..a775715 100644 --- a/src/Serilog.Sinks.Email/Sinks/Email/SystemMailEmailTransport.cs +++ b/src/Serilog.Sinks.Email/Sinks/Email/SystemMailEmailTransport.cs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#if SYSTEM_NET using System.ComponentModel; using System.Net.Mail; using System.Text; @@ -97,4 +96,3 @@ static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e) } } } -#endif diff --git a/test/Serilog.Sinks.Email.Tests/EmailSinkTests.cs b/test/Serilog.Sinks.Email.Tests/EmailSinkTests.cs index f4773b2..b15aaf2 100644 --- a/test/Serilog.Sinks.Email.Tests/EmailSinkTests.cs +++ b/test/Serilog.Sinks.Email.Tests/EmailSinkTests.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Net; using System.Threading.Tasks; -using Serilog.Formatting; using Xunit; namespace Serilog.Sinks.Email.Tests @@ -113,20 +112,16 @@ await emailSink.EmitBatchAsync(new[] { Assert.Equal("[Error] A multiline" + Environment.NewLine + "Message" + Environment.NewLine + "System.ArgumentOutOfRangeException: Message of the exception" -#if NEW_ARGUMENTOUTOFRANGEEXCEPTION_MESSAGE + + " (Parameter 'parameter1')" -#else - + Environment.NewLine + "Parameter name: parameter1" -#endif + + Environment.NewLine + "", actual.Body); Assert.Equal(@"[Error] A multiline" + Environment.NewLine + "Message" + Environment.NewLine + "System.ArgumentOutOfRangeException: Message of the exception" -#if NEW_ARGUMENTOUTOFRANGEEXCEPTION_MESSAGE + + " (Parameter 'parameter1')" -#else - + Environment.NewLine + "Parameter name: parameter1" -#endif + + Environment.NewLine + "", actual.Subject); Assert.Equal("from@localhost.local", actual.From); Assert.Equal(new[] { "to@localhost.local" }, actual.To); diff --git a/test/Serilog.Sinks.Email.Tests/Serilog.Sinks.Email.Tests.csproj b/test/Serilog.Sinks.Email.Tests/Serilog.Sinks.Email.Tests.csproj index 1b86569..2627e84 100644 --- a/test/Serilog.Sinks.Email.Tests/Serilog.Sinks.Email.Tests.csproj +++ b/test/Serilog.Sinks.Email.Tests/Serilog.Sinks.Email.Tests.csproj @@ -1,7 +1,7 @@  - net45;net47;netcoreapp2.2;netcoreapp3.1 + net6.0 Serilog.Sinks.Email.Tests ../../assets/Serilog.snk true @@ -15,49 +15,17 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers - - - - - - - - - - - - - - - - $(DefineConstants);SYSTEM_NET - - - $(DefineConstants);SYSTEM_NET - - - - $(DefineConstants);MAIL_KIT - - - $(DefineConstants);MAIL_KIT;NEW_ARGUMENTOUTOFRANGEEXCEPTION_MESSAGE - - - + - - - -