Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MailKitSender] Per client ServerCertificateValidationCallback #338

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
13 changes: 13 additions & 0 deletions src/Senders/FluentEmail.MailKit/MailKitSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using MimeKit;
using System;
using System.IO;
using System.Net.Security;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -54,6 +55,12 @@ public SendResponse Send(IFluentEmail email, CancellationToken? token = null)

using (var client = new SmtpClient())
{
client.CheckCertificateRevocation = _smtpClientOptions.CheckCertificateRevocation;
if(_smtpClientOptions.ServerCertificateValidationCallback != null)
{
client.ServerCertificateValidationCallback = _smtpClientOptions.ServerCertificateValidationCallback;
}

if (_smtpClientOptions.SocketOptions.HasValue)
{
client.Connect(
Expand Down Expand Up @@ -116,6 +123,12 @@ public async Task<SendResponse> SendAsync(IFluentEmail email, CancellationToken?

using (var client = new SmtpClient())
{
client.CheckCertificateRevocation = _smtpClientOptions.CheckCertificateRevocation;
if (_smtpClientOptions.ServerCertificateValidationCallback != null)
{
client.ServerCertificateValidationCallback = _smtpClientOptions.ServerCertificateValidationCallback;
}

if (_smtpClientOptions.SocketOptions.HasValue)
{
await client.ConnectAsync(
Expand Down
3 changes: 3 additions & 0 deletions src/Senders/FluentEmail.MailKit/SmtpClientOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MailKit.Security;
using System.Net.Security;

namespace FluentEmail.MailKitSmtp
{
Expand All @@ -14,5 +15,7 @@ public class SmtpClientOptions
public bool UsePickupDirectory { get; set; } = false;
public string MailPickupDirectory { get; set; } = string.Empty;
public SecureSocketOptions? SocketOptions { get; set; }
public bool CheckCertificateRevocation { get; set; } = true;
public RemoteCertificateValidationCallback ServerCertificateValidationCallback { get; set; }
}
}