SMTP and templated email sender implementation for NPv.Mail.Abstractions. Provides MailKit-based delivery, Scriban-based template rendering, and seamless configuration via Microsoft.Extensions.Options. Designed for clean architecture, DI integration, and testability.
$ dotnet add package NPv.MailSMTP and templated email sender implementation for NPv.Mail.Abstractions.
net10.0 (dropped net9.0 support).This is a personal library that focuses on the latest .NET runtime to keep maintenance simple and enjoyable.
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.SmtpSettings with IOptions<T> integration.NPv.Mail.Abstractions interfaces and fits naturally into DI.Use this package in your application or infrastructure layers to actually deliver messages defined through abstractions.
dotnet add package NPv.Mail
You also need the abstractions:
dotnet add package NPv.Mail.Abstractions
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"
}
builder.Services.Configure<SmtpSettings>(
builder.Configuration.GetSection("Smtp"));
builder.Services.AddTransient<IMailSender, MailKitMailSender>();
builder.Services.AddTransient<IEmailTemplateRenderer>(sp =>
new ScribanEmailTemplateRenderer([typeof(Program).Assembly]));
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);
var renderer = app.Services.GetRequiredService<IEmailTemplateRenderer>();
var content = renderer.Render(new ConfirmEmailTemplateModel(confirmUrl, "en"));
Console.WriteLine(content.Subject);
Console.WriteLine(content.HtmlBody);
NPv.Mail.Abstractions – contracts and DTOsNPv.DataAccess.Ef – EF Core repository infrastructureNPv.DataAccess.Dapper.Executor – raw SQL execution via DapperThis 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 :-P
MIT — free for commercial and open-source use.