TailoredApps.Shared.Email 3.0.0-preview.2

This is a prerelease version of TailoredApps.Shared.Email.
dotnet add package TailoredApps.Shared.Email --version 3.0.0-preview.2
                    
NuGet\Install-Package TailoredApps.Shared.Email -Version 3.0.0-preview.2
                    
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="TailoredApps.Shared.Email" Version="3.0.0-preview.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TailoredApps.Shared.Email" Version="3.0.0-preview.2" />
                    
Directory.Packages.props
<PackageReference Include="TailoredApps.Shared.Email" />
                    
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 TailoredApps.Shared.Email --version 3.0.0-preview.2
                    
#r "nuget: TailoredApps.Shared.Email, 3.0.0-preview.2"
                    
#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 TailoredApps.Shared.Email@3.0.0-preview.2
                    
#: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=TailoredApps.Shared.Email&version=3.0.0-preview.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=TailoredApps.Shared.Email&version=3.0.0-preview.2&prerelease
                    
Install as a Cake Tool

TailoredApps.Shared.Email

Sending e-mail behind one interface, IEmailProvider. The package contains an SMTP provider, a console provider for development, and IMailMessageBuilder implementations that build a message body from a template and a dictionary of variables.

Installation

dotnet add package TailoredApps.Shared.Email

Registration

using TailoredApps.Shared.Email;
using TailoredApps.Shared.Email.MailMessageBuilder;

builder.Services.RegisterSmtpProvider();          // IEmailProvider -> SmtpEmailProvider (transient)
// builder.Services.RegisterConsoleProvider();    // IEmailProvider -> EmailServiceToConsolleWritter (writes to the console)

// Message bodies from template files. No IMailMessageBuilder is registered unless you add one.
builder.Services.Configure<TokenReplacingMailMessageBuilderOptions>(options =>
{
    options.Location = Path.Combine(builder.Environment.ContentRootPath, "EmailTemplates");
    options.FileExtension = "html";
});
builder.Services.AddTransient<IMailMessageBuilder, TokenReplacingMailMessageBuilder>();

Usage

public class WelcomeMailSender(IEmailProvider email, IMailMessageBuilder builder)
{
    // EmailTemplates/welcome.html: <h1>Hello, {{UserName}}!</h1>
    public Task<string> Send(string address, string userName)
    {
        var body = builder.Build("welcome.html", new Dictionary<string, string> { ["UserName"] = userName }, null);

        return email.SendMail(address, "Welcome", body, attachments: null);   // or file name -> byte[]
    }
}

Configuration

SmtpEmailProvider reads the Mail:Providers:Smtp section:

{
  "Mail": {
    "Providers": {
      "Smtp": {
        "Host": "smtp.example.com",
        "Port": 587,
        "UserName": "noreply@example.com",
        "Password": "<smtp-password>",
        "From": "noreply@example.com",
        "IsProd": true,
        "CatchAll": "developers@example.com"
      }
    }
  }
}
Key Meaning Default
Host, Port SMTP server address and port none, 0
UserName, Password Credentials sent to the server none
From Sender address (From and Sender headers); required none
EnableSsl Encrypt the connection true
IsProd true: send to the given recipient; false: send everything to CatchAll false
CatchAll Address that receives all mail when IsProd is false; required in that case none

TokenReplacingMailMessageBuilderOptions is set in code: Location (template directory), FileExtension (without the dot; empty means every file) and HtmlEncodeVariables (default true).

Good to know

  • IsProd defaults to false: until it is set, every message goes to CatchAll, and a missing CatchAll throws InvalidOperationException. A missing Mail:Providers:Smtp section throws InvalidOperationException when the options are first read; a missing From throws ArgumentNullException.
  • SendMail takes exactly one recipient. An address containing ,, ; or a line break throws FormatException. It returns the Message-ID header it generated for the message.
  • Bodies are sent as HTML in UTF-8. TokenReplacingMailMessageBuilder HTML-encodes {{Token}} values, inserts {{{Token}}} values as they are, leaves unknown tokens untouched and replaces in a single pass.
  • The template key is the file name with its extension. Location is searched with its sub-directories and read on every Build call. An unknown key throws KeyNotFoundException.
  • DefaultMessageBuilder works on the templates dictionary passed to Build and replaces the variable keys as plain text (no braces), HTML-encoding the values unless created with htmlEncodeVariables: false.
  • SmtpEmailProvider.GetMail is not implemented (NotImplementedException); the console provider returns an empty list. Reading a mailbox is what TailoredApps.Shared.Email.Office365 does.

Documentation

https://shared.tailoredapps.pl/en/Libraries/Email/

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

NuGet packages (2)

Showing the top 2 NuGet packages that depend on TailoredApps.Shared.Email:

Package Downloads
TailoredApps.Shared.MediatR.Email

Package Description

TailoredApps.Shared.Email.Office365

Shared.Email.Office365 is a simple Office365 for Email for .NET

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0-preview.2 53 11/12/2026
3.0.0-preview.1 65 11/12/2026
2.1.0 111 11/12/2026
2.0.1 105 11/12/2026
2.0.0 131 11/12/2026
1.6.0 129 11/12/2026
1.4.19 513 10/26/2026
1.4.18 606 10/23/2026
1.4.17 797 10/6/2026
1.4.16 141 9/28/2026
1.4.15 149 9/21/2026
1.4.14 175 8/20/2026
1.4.13 175 8/20/2026
1.4.12 174 8/20/2026
1.4.11 167 8/7/2026
1.4.10 273 7/8/2026
1.4.9 182 7/8/2026
1.4.8 182 7/6/2026
1.4.7 197 5/20/2026
1.4.6 184 5/20/2026
Loading failed