Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/NETCore.MailKit/Core/EmailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using MimeKit.Text;
using NETCore.MailKit.Infrastructure.Internal;
using NETCore.MailKit.Shared;
using System;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -297,7 +298,18 @@ private void SendEmail(string mailTo, string mailCc, string mailBcc, string subj

using (var client = _MailKitProvider.SmtpClient)
{
client.Send(mimeMessage);
try
{
client?.Send(mimeMessage);
}
catch (Exception ex)
{
throw ex;
}
finally
{
client?.Disconnect(true);
}
}
}
}
Expand Down
54 changes: 32 additions & 22 deletions src/NETCore.MailKit/MailKitProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,42 @@ private Lazy<SmtpClient> lazySmtpClient()

private SmtpClient InitSmtpClient()
{
var client = new SmtpClient();

client.ServerCertificateValidationCallback = (s, c, h, e) => true;


if (!Options.Security)
try
{
client.Connect(Options.Server, Options.Port, SecureSocketOptions.None);
var client = new SmtpClient();

client.CheckCertificateRevocation = false;
//����timeout ���ⳤʱ��ĵȴ�
client.Timeout = 5000;
client.ServerCertificateValidationCallback = (s, c, h, e) => true;


if (!Options.Security)
{
client.Connect(Options.Server, Options.Port, SecureSocketOptions.None);
}
else
{
// fix issue #6
client.Connect(Options.Server, Options.Port, SecureSocketOptions.Auto);
}

// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");

// user login smtp server (fix issue #9)
if (!string.IsNullOrEmpty(Options.Account) && !string.IsNullOrEmpty(Options.Password))
{
client.Authenticate(Options.Account, Options.Password);
}

return client;
}
else
catch(Exception e)
{
// fix issue #6
client.Connect(Options.Server, Options.Port, SecureSocketOptions.Auto);
throw e;
}

// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");

// user login smtp server (fix issue #9)
if (!string.IsNullOrEmpty(Options.Account) && !string.IsNullOrEmpty(Options.Password))
{
client.Authenticate(Options.Account, Options.Password);
}

return client;
}

#endregion
Expand Down
15 changes: 8 additions & 7 deletions src/NETCore.MailKit/NETCore.MailKit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>2.1.0</Version>
<Authors>Lvcc</Authors>
<Version>2.1.2</Version>
<Authors>jason</Authors>
<Company />
<Description>MailKit extension for asp.net core. Easy send email in asp.net core project.</Description>
<Copyright>Copyright 2017 (c) Lvcc. All rights reserved</Copyright>
<PackageProjectUrl>https://github.com/myloveCc/NETCore.MailKit</PackageProjectUrl>
<RepositoryUrl>https://github.com/myloveCc/NETCore.MailKit</RepositoryUrl>
<Copyright>Copyright 2023 (c) Flame. All rights reserved</Copyright>
<PackageProjectUrl>https://github.com/mswinner/NETCore.MailKit2</PackageProjectUrl>
<RepositoryUrl>https://github.com/mswinner/NETCore.MailKit2</RepositoryUrl>
<PackageTags>MailKit ASP.NETCore</PackageTags>
<RepositoryType>git</RepositoryType>
<AssemblyVersion>2.1.0</AssemblyVersion>
<FileVersion>2.1.0</FileVersion>
<AssemblyVersion>2.1.1</AssemblyVersion>
<FileVersion>2.1.1</FileVersion>
<PackageReleaseNotes>
1: Update Mailkit to version 3.2.0.
2: Adds support for sending emails with attachments. #19
3: Update example sdk to .NET 6</PackageReleaseNotes>
<PackageId>Flame.MailKit</PackageId>
</PropertyGroup>

<ItemGroup>
Expand Down