PostKit 9.0.0-preview.3
This is a prerelease version of PostKit.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package PostKit --version 9.0.0-preview.3
NuGet\Install-Package PostKit -Version 9.0.0-preview.3
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="PostKit" Version="9.0.0-preview.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PostKit" Version="9.0.0-preview.3" />
<PackageReference Include="PostKit" />
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 PostKit --version 9.0.0-preview.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: PostKit, 9.0.0-preview.3"
#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 PostKit@9.0.0-preview.3
#: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=PostKit&version=9.0.0-preview.3&prerelease
#tool nuget:?package=PostKit&version=9.0.0-preview.3&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
PostKit
A MimeKit infused implementation of the Postmark API.
Quickstart
Prerequisites
- .NET 9.0 or later
- A Postmark account with a Server API Token
- Verified sender email addresses in your Postmark account
Installation
Install PostKit via NuGet:
dotnet add package PostKit
Configuration
Add PostKit to your services and configure your Postmark API token:
// Program.cs (Minimal API / Web App)
using PostKit;
var builder = WebApplication.CreateBuilder(args);
// Add PostKit to services
builder.Services.AddPostKit();
var app = builder.Build();
Configure your Postmark Server API Token in appsettings.json:
{
"PostKit": {
"ServerApiToken": "your-postmark-server-token-here"
}
}
Or set it via environment variables:
PostKit__ServerApiToken=your-postmark-server-token-here
Basic Usage
Simple Email
using PostKit;
// Inject IPostKitClient via dependency injection
public class EmailService
{
private readonly IPostKitClient _postKitClient;
public EmailService(IPostKitClient postKitClient)
{
_postKitClient = postKitClient;
}
public async Task SendWelcomeEmailAsync()
{
var email = Email.CreateBuilder()
.From("noreply@yourapp.com")
.To("user@example.com")
.WithSubject("Welcome to Our Service!")
.WithTextBody("Thank you for signing up!")
.Build();
await _postKitClient.SendEmailAsync(email);
}
}
Rich HTML Email
var email = Email.CreateBuilder()
.From("Sarah Johnson", "sarah@company.com")
.To("customer@example.com")
.WithSubject("Your Order Confirmation")
.WithHtmlBody(@"
<h1>Order Confirmed!</h1>
<p>Thank you for your purchase. Your order #12345 has been confirmed.</p>
<a href='https://yourapp.com/orders/12345'>View Order Details</a>
")
.WithTextBody("Order Confirmed! Thank you for your purchase. Your order #12345 has been confirmed. View details at: https://yourapp.com/orders/12345")
.Build();
await _postKitClient.SendEmailAsync(email);
Multiple Recipients
var email = Email.CreateBuilder()
.From("notifications@company.com")
.To(new[] { "user1@example.com", "user2@example.com" })
.Cc("manager@company.com")
.Bcc("admin@company.com")
.WithSubject("Team Update")
.WithTextBody("Important team announcement...")
.Build();
await _postKitClient.SendEmailAsync(email);
Advanced Features
var email = Email.CreateBuilder()
.From("newsletter@company.com")
.To("subscriber@example.com")
.ReplyTo("support@company.com")
.WithSubject("Monthly Newsletter")
.WithHtmlBody("<h1>Newsletter</h1><p>Check out our latest updates!</p>")
.WithTag("newsletter")
.WithMetadata("campaign", "monthly-2024")
.WithMetadata("segment", "premium-users")
.WithOpenTracking(true)
.WithLinkTracking(LinkTracking.HtmlAndText)
.UsingMessageStream(MessageStream.Broadcast)
.WithHeader("X-Campaign-ID", "CAMP-001")
.Build();
await _postKitClient.SendEmailAsync(email);
Builder Pattern Features
PostKit uses a fluent builder pattern with the following capabilities:
- Email Addresses: Support for simple strings, name/address pairs, or MimeKit
MailboxAddressobjects - Multiple Recipients: Chain
AlsoTo(),AlsoCc(), orAlsoBcc()to add additional recipients - Validation: Automatic validation of email addresses, character limits, and required fields
- Flexible API: Mix and match any combination of features
Error Handling
PostKit uses structured logging and handles errors gracefully:
try
{
await _postKitClient.SendEmailAsync(email);
// Email sent successfully - check logs for details
}
catch (Exception ex)
{
// Handle any unexpected errors
// PostKit will log detailed error information automatically
}
Message Streams
Postmark supports different message streams for different types of emails:
// For transactional emails (default)
.UsingMessageStream(MessageStream.Transactional)
// For broadcast/marketing emails
.UsingMessageStream(MessageStream.Broadcast)
// Or use a custom stream ID
.UsingMessageStream("custom-stream-id")
Complete Console Application Example
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using PostKit;
var builder = Host.CreateApplicationBuilder(args);
// Add PostKit
builder.Services.AddPostKit();
var host = builder.Build();
// Get the PostKit client
var postKitClient = host.Services.GetRequiredService<IPostKitClient>();
// Create and send an email
var email = Email.CreateBuilder()
.From("test@yourapp.com")
.To("recipient@example.com")
.WithSubject("Test Email from PostKit")
.WithTextBody("Hello from PostKit! This email was sent using the PostKit library.")
.WithHtmlBody("<h1>Hello from PostKit!</h1><p>This email was sent using the <strong>PostKit</strong> library.</p>")
.Build();
await postKitClient.SendEmailAsync(email);
Console.WriteLine("Email sent successfully!");
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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.
-
net9.0
- JetBrains.Annotations (>= 2025.2.2)
- LightResults (>= 9.0.5)
- Microsoft.Extensions.Http (>= 9.0.9)
- Microsoft.Extensions.Telemetry.Abstractions (>= 9.9.0)
- MimeKit (>= 4.13.0)
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 |
|---|---|---|
| 10.0.1 | 2,242 | 12/22/2025 |
| 10.0.0 | 2,660 | 12/16/2025 |
| 10.0.0-preview.1 | 557 | 11/15/2025 |
| 9.0.0-preview.7 | 374 | 10/13/2025 |
| 9.0.0-preview.6 | 146 | 10/13/2025 |
| 9.0.0-preview.5 | 638 | 10/8/2025 |
| 9.0.0-preview.4 | 167 | 9/24/2025 |
| 9.0.0-preview.3 | 152 | 9/24/2025 |
| 9.0.0-preview.2 | 903 | 12/22/2024 |
| 9.0.0-preview.1 | 102 | 12/21/2024 |