Pinqponq.Mail 1.0.1

Prefix Reserved
dotnet add package Pinqponq.Mail --version 1.0.1
                    
NuGet\Install-Package Pinqponq.Mail -Version 1.0.1
                    
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="Pinqponq.Mail" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pinqponq.Mail" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Pinqponq.Mail" />
                    
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 Pinqponq.Mail --version 1.0.1
                    
#r "nuget: Pinqponq.Mail, 1.0.1"
                    
#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 Pinqponq.Mail@1.0.1
                    
#: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=Pinqponq.Mail&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Pinqponq.Mail&version=1.0.1
                    
Install as a Cake Tool

Pinqponq.Mail

SMTP-based email sending wrapper with a standard IEmailSender interface, built directly on System.Net.Mail — no third-party mail client dependency. Supports comma/semicolon-separated To/Cc/Bcc lists and file attachments confined to a configured root directory.

Install

dotnet add package Pinqponq.Mail

Requirements

  • .NET 8.0, 9.0, or 10.0
  • An SMTP server (host, port, and optionally credentials)

Quick start

Configure inline:

using Pinqponq.Mail;
using Pinqponq.Mail.DependencyInjection;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddPinqponqMail(options =>
{
    options.SmtpHost = "smtp.example.com";
    options.SmtpPort = 587;
    options.SmtpUsername = builder.Configuration["Smtp:Username"];
    options.SmtpPassword = builder.Configuration["Smtp:Password"];
    options.FromEmail = "no-reply@example.com";
    options.FromName = "My App";
});

var app = builder.Build();

...or bind from configuration (defaults to the "Smtp" section):

builder.Services.AddPinqponqMail(builder.Configuration);
// or a custom section name:
builder.Services.AddPinqponqMail(builder.Configuration, sectionName: "Mail:Smtp");
{
  "Smtp": {
    "SmtpHost": "smtp.example.com",
    "SmtpPort": 587,
    "SmtpUsername": "apikey",
    "SmtpPassword": "secret",
    "FromEmail": "no-reply@example.com",
    "FromName": "My App",
    "EnableSsl": true
  }
}

Send a message from anywhere IEmailSender is injected:

public sealed class WelcomeEmailService(IEmailSender emailSender)
{
    public Task SendAsync(string to, CancellationToken cancellationToken) =>
        emailSender.SendAsync(
            new EmailMessage
            {
                To = to,
                Subject = "Welcome!",
                Body = "<p>Thanks for signing up.</p>",
                IsBodyHtml = true,
            },
            cancellationToken);
}

Configuration

Two overloads of AddPinqponqMail register IEmailSender (as SmtpEmailSender) and validate SmtpOptions on startup via ValidateOnStart():

  • AddPinqponqMail(Action<SmtpOptions> configure) — inline configuration.
  • AddPinqponqMail(IConfiguration configuration, string sectionName = "Smtp") — binds from a configuration section. Throws InvalidOperationException at registration time if the section doesn't exist.
Option Default Notes
SmtpHost "" Required.
SmtpPort 0 Required; must be between 1 and 65535.
SmtpUsername "" Optional. When set, SmtpClient.Credentials is configured with it (and SmtpPassword); when blank, the connection is anonymous.
SmtpPassword "" Paired with SmtpUsername.
FromEmail "" Required. Used as the From address on every outgoing message.
FromName null Optional From display name.
EnableSsl true Whether SmtpClient uses SSL/TLS.
AttachmentRoot null Root directory that attachment paths must resolve under. Required when EmailMessage.Attachments is non-empty — see Notes / behavior.

SmtpOptionsValidator (an internal IValidateOptions<SmtpOptions>) enforces SmtpHost, SmtpPort, and FromEmail at startup; a missing AttachmentRoot is only surfaced later, when a message with attachments is actually sent.

Main types

  • AddPinqponqMailIServiceCollection extensions (inline or IConfiguration-bound) that register IEmailSender and its options.
  • IEmailSender — the sending contract: Task SendAsync(EmailMessage message, CancellationToken cancellationToken = default).
  • EmailMessageTo and Subject/Body are required; Cc, Bcc are optional comma/semicolon-separated address lists; IsBodyHtml defaults to true; Attachments is an optional list of file paths.
  • SmtpOptions — configuration as described above.
  • SmtpEmailSender — the IEmailSender implementation, built on System.Net.Mail.SmtpClient and MailMessage.

Notes / behavior

  • Attachments require AttachmentRoot — this is a path jail, not just a config toggle. If EmailMessage.Attachments is non-empty but SmtpOptions.AttachmentRoot is blank, SendAsync throws ArgumentException immediately. When AttachmentRoot is set, every attachment path is resolved with Path.GetFullPath and must land inside that root directory (or equal it exactly); a path that resolves outside the root — including via .. traversal — is rejected with ArgumentException rather than being opened. A path that doesn't exist on disk after resolution also throws ArgumentException. This exists to stop caller-supplied paths from being used to read arbitrary files off the host as "attachments."
  • To/Cc/Bcc accept lists. Each is split on , and ;, trimmed, and empty entries are dropped. To must resolve to at least one address or SendAsync throws ArgumentException.
  • Validation order: recipient, subject, and body are checked before any SMTP connection is attempted; attachment path validation happens after that, still before the message is sent.
  • No built-in retry: unlike Pinqponq.Sms, this package does not wrap sends in a Polly retry pipeline — SmtpClient.SendMailAsync failures propagate directly. Add your own retry policy around IEmailSender.SendAsync if you need one.
  • Because it's built on System.Net.Mail, this package requires no external SMTP client library, but also inherits SmtpClient's behavior and limitations (e.g. synchronous DNS/connection setup, no built-in connection pooling across calls).
  • Pinqponq.Identity.Otp — sends one-time passwords over email (and SMS) using this package's IEmailSender as its email delivery channel.

Samples

Try this package in the browser via Pinqponq.Playground — see samples/README.md.

Repository

https://github.com/pinqponq/pinqnuqets

Product 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 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Pinqponq.Mail:

Package Downloads
Pinqponq.Identity.Otp

One-time code send/verify flow over email or SMS; channel routing (mail/sms) lives in the package. Storage interface is left to the consumer.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 262 8/7/2026
1.0.0 117 8/7/2026