NPv.Mail
2.1.1
dotnet add package NPv.Mail --version 2.1.1
NuGet\Install-Package NPv.Mail -Version 2.1.1
<PackageReference Include="NPv.Mail" Version="2.1.1" />
<PackageVersion Include="NPv.Mail" Version="2.1.1" />
<PackageReference Include="NPv.Mail" />
paket add NPv.Mail --version 2.1.1
#r "nuget: NPv.Mail, 2.1.1"
#:package NPv.Mail@2.1.1
#addin nuget:?package=NPv.Mail&version=2.1.1
#tool nuget:?package=NPv.Mail&version=2.1.1
NPv.Mail
SMTP and templated email sender implementation for NPv.Mail.Abstractions.
π Breaking changes
v2.0.0
- Target framework updated to
net10.0(droppednet9.0support).
This is a personal library that focuses on the latest .NET runtime to keep maintenance simple and enjoyable.
β¨ Overview
NPv.Mail provides a ready-to-use implementation for sending emails and rendering templates:
- π§
MailKitMailSenderβ SMTP sender powered by MailKit and MimeKit. - π
ScribanEmailTemplateRendererβ template rendering engine based on Scriban. - βοΈ Options binding β strongly typed
SmtpSettingswithIOptions<T>integration. - π Designed for clean architecture β works with
NPv.Mail.Abstractionsinterfaces and fits naturally into DI.
Use this package in your application or infrastructure layers to actually deliver messages defined through abstractions.
π Getting Started
1. Installation
dotnet add package NPv.Mail
You also need the abstractions:
dotnet add package NPv.Mail.Abstractions
2. Configuration
Add SMTP settings to your appsettings.json:
"Smtp": {
"ServerName": "smtp.example.com",
"ServerPort": 587,
"UserName": "user@example.com",
"Password": "yourpassword",
"FromAddress": "noreply@example.com",
"FromName": "Example Sender"
}
3. Register Services
builder.Services.Configure<SmtpSettings>(
builder.Configuration.GetSection("Smtp"));
builder.Services.AddTransient<IMailSender, MailKitMailSender>();
builder.Services.AddTransient<IEmailTemplateRenderer>(sp =>
new ScribanEmailTemplateRenderer([typeof(Program).Assembly]));
4. Send an Email
var sender = app.Services.GetRequiredService<IMailSender>();
var message = new MailRequest
{
To = "recipient@example.com",
Subject = "Welcome!",
HtmlBody = "<p>Hello world!</p>",
Attachments =
[
new MailAttachment
{
FileName = "hello.txt",
Content = Encoding.UTF8.GetBytes("Hello world!"),
ContentType = "text/plain"
}
]
};
await sender.SendAsync(message);
5. Render a Template
var renderer = app.Services.GetRequiredService<IEmailTemplateRenderer>();
var content = renderer.Render(new ConfirmEmailTemplateModel(confirmUrl, "en"));
Console.WriteLine(content.Subject);
Console.WriteLine(content.HtmlBody);
π Related Packages
NPv.Mail.Abstractionsβ contracts and DTOsNPv.DataAccess.Efβ EF Core repository infrastructureNPv.DataAccess.Dapper.Executorβ raw SQL execution via Dapper
Author's Note
This library grew out of my long-standing personal interest in structuring and publishing open source packages. Over time, Iβve revisited and refined earlier internal utilities and ideas, giving them a more consistent shape and preparing them for wider reuse. Along the way, Iβve also taken the opportunity to explore how open source distribution and licensing work in the .NET ecosystem.
Itβs a small step toward something Iβve always wanted to try β sharing practical, minimal tools that reflect years of learning, experimentation, and refinement.
Hopefully, someone finds it useful.
Nikolai π
βοΈ License
MIT β free for commercial and open-source use.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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.Options.ConfigurationExtensions (>= 10.0.3)
- MimeKit (>= 4.16.0)
- NPv.Mail.Abstractions (>= 2.1.0)
- Scriban (>= 7.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.