IdempotentCookie.Email
0.1.0
dotnet add package IdempotentCookie.Email --version 0.1.0
NuGet\Install-Package IdempotentCookie.Email -Version 0.1.0
<PackageReference Include="IdempotentCookie.Email" Version="0.1.0" />
<PackageVersion Include="IdempotentCookie.Email" Version="0.1.0" />
<PackageReference Include="IdempotentCookie.Email" />
paket add IdempotentCookie.Email --version 0.1.0
#r "nuget: IdempotentCookie.Email, 0.1.0"
#:package IdempotentCookie.Email@0.1.0
#addin nuget:?package=IdempotentCookie.Email&version=0.1.0
#tool nuget:?package=IdempotentCookie.Email&version=0.1.0
IdempotentCookie.Email
Unified email delivery package for .NET.
Supports SMTP, Mailgun, and SendGrid through one public NuGet package.
Configure one provider per application. No failover is built in.
Supported Providers
- SMTP
- Mailgun
- SendGrid
Install
- Run
dotnet add package IdempotentCookie.Email. - Import
IdempotentCookie.Emailplus the provider namespace you need.
If you bind provider settings from configuration outside an ASP.NET Core Web SDK app, also add:
dotnet add package Microsoft.Extensions.Configuration.Binderdotnet add package Microsoft.Extensions.Options.ConfigurationExtensionsdotnet add package Microsoft.Extensions.Options.DataAnnotations
Register With Dependency Injection
- Import the DI namespace and one provider namespace.
- Register exactly one provider in
Program.cs. - Resolve
IEmailClientwhere you need to send mail.
using IdempotentCookie.Email.DependencyInjection;
using IdempotentCookie.Email.Smtp;
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddEmailSending()
.UseSmtp(new SmtpClientConfig
{
Host = "smtp.example.com",
Port = 587,
Security = SmtpConnectionSecurity.StartTls,
UserName = "mailer",
Password = "secret"
});
If you prefer to hydrate SMTP settings from configuration, bind the section once during startup, validate it, then pass the bound config into UseSmtp(...). The library does not define a built-in section name, so pick one such as Email:Smtp.
using IdempotentCookie.Email.DependencyInjection;
using IdempotentCookie.Email.Smtp;
using Microsoft.Extensions.Configuration;
var builder = WebApplication.CreateBuilder(args);
const string smtpSectionName = "Email:Smtp";
builder.Services
.AddOptions<SmtpClientConfig>()
.Bind(builder.Configuration.GetRequiredSection(smtpSectionName))
.ValidateDataAnnotations()
.ValidateOnStart();
var smtpConfig = new SmtpClientConfig();
builder.Configuration.GetRequiredSection(smtpSectionName).Bind(smtpConfig);
smtpConfig.Validate();
builder.Services
.AddEmailSending()
.UseSmtp(smtpConfig);
Send With Dependency Injection
- Inject
IEmailClient. - Build an
EmailMessage. - Call
SendAsync.
using IdempotentCookie.Email;
public sealed class WelcomeEmailSender(IEmailClient emailClient)
{
public async Task SendWelcomeEmailAsync(CancellationToken cancellationToken)
{
var message = new EmailMessage
{
From = new EmailAddress { Address = "sender@example.com", Name = "Sender" },
Subject = "Hello",
TextBody = "Hello from IdempotentCookie.Email",
HtmlBody = "<p>Hello from IdempotentCookie.Email</p>"
};
message.ToRecipients.Add(new EmailAddress
{
Address = "recipient@example.com",
Name = "Recipient"
});
await emailClient.SendAsync(message, cancellationToken);
}
}
Send With Attachments
- Build the message as usual.
- Add one or more
EmailAttachmentitems tomessage.Attachments. - Send via
IEmailClient.
using IdempotentCookie.Email;
using System.IO;
public sealed class InvoiceEmailSender(IEmailClient emailClient)
{
public async Task SendInvoiceAsync(CancellationToken cancellationToken)
{
var message = new EmailMessage
{
From = new EmailAddress { Address = "billing@example.com", Name = "Billing" },
Subject = "Your invoice",
TextBody = "Please find your invoice attached.",
HtmlBody = "<p>Please find your invoice attached.</p>"
};
message.ToRecipients.Add(new EmailAddress
{
Address = "recipient@example.com",
Name = "Recipient"
});
message.Attachments.Add(new EmailAttachment
{
FileName = "invoice-2026-04.pdf",
ContentType = "application/pdf",
Content = File.ReadAllBytes("./invoices/invoice-2026-04.pdf")
});
await emailClient.SendAsync(message, cancellationToken);
}
}
Use Without Dependency Injection
- Create a provider configuration object.
- Call
CreateClient(). - Send the message through
IEmailClient.
using IdempotentCookie.Email;
using IdempotentCookie.Email.Mailgun;
public sealed class MailgunSmokeTest
{
public async Task RunAsync(CancellationToken cancellationToken)
{
var config = new MailgunClientConfig
{
ApiKey = "key-...",
SendingDomain = "mg.example.com"
};
var message = new EmailMessage
{
From = new EmailAddress { Address = "sender@example.com", Name = "Sender" },
Subject = "Hello",
TextBody = "Hello from IdempotentCookie.Email"
};
message.ToRecipients.Add(new EmailAddress { Address = "recipient@example.com", Name = "Recipient" });
IEmailClient client = config.CreateClient();
await client.SendAsync(message, cancellationToken);
}
}
Provider Namespaces
IdempotentCookie.Email.DependencyInjectionIdempotentCookie.Email.SmtpIdempotentCookie.Email.MailgunIdempotentCookie.Email.SendGrid
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 was computed. 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 is compatible. 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. |
-
net10.0
- MailKit (>= 4.16.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.6)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.6)
- MimeKit (>= 4.16.0)
- SendGrid (>= 9.29.3)
-
net8.0
- MailKit (>= 4.16.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.6)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.6)
- MimeKit (>= 4.16.0)
- SendGrid (>= 9.29.3)
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 |
|---|---|---|
| 0.1.0 | 126 | 4/16/2026 |
| 0.1.0-rc.1 | 67 | 4/4/2026 |
Initial prerelease candidate with unified SMTP, Mailgun, and SendGrid providers, optional DI integration, and attachment support.