PollyMailKit 1.0.0

dotnet add package PollyMailKit --version 1.0.0
                    
NuGet\Install-Package PollyMailKit -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PollyMailKit" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PollyMailKit" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="PollyMailKit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PollyMailKit --version 1.0.0
                    
#r "nuget: PollyMailKit, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PollyMailKit@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PollyMailKit&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=PollyMailKit&version=1.0.0
                    
Install as a Cake Tool

PollyMailKit

NuGet NuGet Downloads CI License: MIT

Polly v8 resilience pipelines for MailKit SMTP — retry, timeout, and circuit-breaker for sending email via SmtpClient.

Why PollyMailKit?

SMTP is inherently flaky. Connections drop, servers throttle, and ServiceNotConnectedException is thrown mid-send. PollyMailKit wraps MailKit's SmtpClient in a Polly v8 ResiliencePipeline so you get automatic retry, exponential back-off, and circuit-breaking with zero boilerplate.

Two wrapper styles:

  • ResilientSmtpSender — creates a fresh connection per attempt (fully retry-safe; recommended for transient failures)
  • ResilientSmtpClient — wraps an existing connected SmtpClient (preferred when the connection lifecycle is managed externally)

Installation

dotnet add package PollyMailKit

Quick start

Option A — ResilientSmtpSender (fresh connection per attempt)

`csharp // Configure in DI services.AddPollyMailKit( new SmtpSettings("smtp.example.com", 587, "user@example.com", "password"), pipeline ⇒ pipeline .AddRetry(new RetryStrategyOptions { MaxRetryAttempts = 3, Delay = TimeSpan.FromSeconds(1), BackoffType = DelayBackoffType.Exponential, ShouldHandle = MailKitTransientErrors.IsTransient, }) .AddTimeout(TimeSpan.FromSeconds(30)));

// Use via DI public class EmailService(ResilientSmtpSender sender) { public async Task SendAsync(MimeMessage message, CancellationToken ct = default) ⇒ await sender.SendAsync(message, ct); } `

Option B — WithPolly() extension on existing SmtpClient

`csharp var smtpClient = new SmtpClient(); await smtpClient.ConnectAsync("smtp.example.com", 587, SecureSocketOptions.Auto); await smtpClient.AuthenticateAsync("user", "password");

var resilient = smtpClient.WithPolly(pipeline ⇒ pipeline.AddRetry(new RetryStrategyOptions { MaxRetryAttempts = 3, Delay = TimeSpan.FromSeconds(1), BackoffType = DelayBackoffType.Exponential, ShouldHandle = MailKitTransientErrors.IsTransient, }));

await resilient.SendAsync(message); `

SmtpSettings

csharp public record SmtpSettings( string Host, int Port, string UserName, string Password, SecureSocketOptions SecureSocketOptions = SecureSocketOptions.Auto);

Transient error predicate

MailKitTransientErrors.IsTransient handles:

Exception Reason
SocketException Network-level failure
IOException Stream read/write error
ServiceNotConnectedException SMTP server disconnected mid-session
OperationCanceledException Timeout or cancellation

Supported frameworks

et6.0 · et8.0 · et9.0

Package Wraps
PollyEFCore Entity Framework Core DbContext
PollyDapper Dapper IDbConnection
PollyMongo MongoDB IMongoCollection<T>
PollyAzureBlob Azure Blob Storage BlobContainerClient
PollyNpgsql Npgsql PostgreSQL NpgsqlConnection
PollySqlClient System.Data.SqlClient SqlConnection
PollyCosmosDb Azure Cosmos DB CosmosClient
PollyGrpc gRPC channel calls
PollyRabbitMQ RabbitMQ IModel channel
PollyAzureServiceBus Azure Service Bus sender/receiver
PollyRedis StackExchange.Redis IDatabase
PollyMediatR MediatR IMediator
PollyOpenAI OpenAI ChatClient
PollyHealthChecks ASP.NET Core health checks
PollyBackoff Pre-built backoff pipelines
PollyChaos Chaos engineering helpers
PollyKafka Confluent Kafka producer/consumer
PollySignalR SignalR HubConnection
PollyRateLimiter .NET rate limiting middleware
PollyElasticsearch Elastic.Clients.Elasticsearch
PollyAzureKeyVault Azure Key Vault SecretClient
PollyAzureEventHub Azure Event Hubs producer
PollySendGrid SendGrid email client
PollyMassTransit MassTransit IBus
PollyAzureTableStorage Azure Table Storage TableClient
PollyAzureQueueStorage Azure Queue Storage QueueClient
PollyHangfire Hangfire IBackgroundJobClient

License

MIT © Justin Bannister

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 48 6/24/2026

1.0.0: Initial release. ResilientSmtpSender creates a fresh connection per attempt (retry-safe). ResilientSmtpClient wraps an existing SmtpClient. MailKitTransientErrors.IsTransient covers SocketException, IOException, ServiceNotConnectedException, OperationCanceledException. Supports net6.0, net8.0, net9.0.