Decode.Email.Abstractions 2.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Decode.Email.Abstractions --version 2.0.1
                    
NuGet\Install-Package Decode.Email.Abstractions -Version 2.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="Decode.Email.Abstractions" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Decode.Email.Abstractions" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Decode.Email.Abstractions" />
                    
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 Decode.Email.Abstractions --version 2.0.1
                    
#r "nuget: Decode.Email.Abstractions, 2.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 Decode.Email.Abstractions@2.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=Decode.Email.Abstractions&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Decode.Email.Abstractions&version=2.0.1
                    
Install as a Cake Tool

Decode.Email.Abstractions

Core contracts, models, and HTML template engine abstractions for email services in the Decode ecosystem.

🚀 Features

  • IEmailService: Framework-agnostic interface for sending email messages and HTML templates across Domain and Application layers.
  • IEmailTemplateEngine: Built-in template engine supporting both Mustache syntax ({{TAG}}) and Hashtag syntax (#TAG#).
  • EmbeddedEmailTemplateProvider: Automatic loading and IMemoryCache caching of embedded .html template resources.
  • Provider-Agnostic Models: Unified EmailMessage, EmailAddress, and EmailAttachment models with metadata support.
  • Shared Template Registration: AddDecodeEmailEmbeddedTemplates lives here, so it can be used with any provider.

📦 Installation

Add the package to your Domain or Application layer:

dotnet add package Decode.Email.Abstractions

📖 Usage

1. Defining Email Templates in Your Project

Create an HTML template file in your project (e.g. EmailTemplates/Welcome.html):

<div style="font-family: Arial, sans-serif; padding: 20px;">
    <h2>Hello, {{NAME}}!</h2>
    <p>Your verification code is: <strong>#CODE#</strong></p>
    <p>This code expires in {{EXPIRATION}}.</p>
</div>

Ensure the .html file is configured as an Embedded Resource in your .csproj:

<ItemGroup>
  <EmbeddedResource Include="EmailTemplates\*.html" />
</ItemGroup>

2. Injecting IEmailService in Application Handlers

Your Domain Services and Handlers only depend on Decode.Email.Abstractions:

using Decode.Email.Abstractions.Interfaces;
using Decode.Email.Abstractions.Models;

public class RegisterCommandHandler(IEmailService emailService)
{
    public async Task HandleAsync(RegisterUserCommand command, CancellationToken ct)
    {
        // Option A: Send HTML template with anonymous object model
        await emailService.SendTemplateAsync(
            to: new EmailAddress(command.Email, command.Name),
            subject: "Welcome to Our Platform",
            templateName: "Welcome",
            model: new
            {
                NAME = command.Name,
                CODE = "998877",
                EXPIRATION = "15 minutes"
            },
            cancellationToken: ct
        );

        // Option B: Send raw email message directly
        EmailMessage message = new()
        {
            From = new EmailAddress("noreply@mydomain.com", "My Application"),
            To = [new EmailAddress(command.Email, command.Name)],
            Subject = "Account Created",
            BodyHtml = "<h1>Your account is ready!</h1>"
        };

        await emailService.SendAsync(message, ct);
    }
}

✉️ Sender Resolution (changed in 2.0.0)

EmailMessage.From is now EmailAddress?. Leave it unset and the provider uses its configured DefaultFromEmail / DefaultFromName:

EmailMessage message = new()
{
    // From omitted — falls back to DefaultFromEmail
    To = [new EmailAddress(command.Email)],
    Subject = "Account Created",
    BodyHtml = "<h1>Your account is ready!</h1>"
};

The property was previously non-nullable and initialized to an empty address, so it was never null and the providers' message.From ?? DefaultFromEmail fallback was unreachable. Configuring a default sender and omitting From raised "Sender email address (From) is required." instead of using it.

Code that reads message.From.Address must now handle null.

🔤 Template Rendering

Placeholders are substituted in a single left-to-right pass, so a substituted value is never rescanned. Before 2.0.0 replacement ran one key at a time across the whole document, which meant caller-supplied data containing {{ResetLink}} was itself expanded into the real reset link.

Values are inserted verbatim by default, because templates commonly pass HTML fragments as model values. When values come from user input, enable encoding:

builder.Services.Configure<EmailTemplateOptions>(o => o.HtmlEncodeValues = true);

📄 License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
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 Decode.Email.Abstractions:

Package Downloads
Decode.Email.Smtp

SMTP email service provider implementation with console dev logger mode for the Decode ecosystem.

Decode.Email.SendGrid

SendGrid API email provider implementation with template engine, ASM unsubscribe groups, and console dev logger mode for the Decode ecosystem.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 120 9/14/2026
2.1.0 142 9/13/2026
2.0.2 143 9/13/2026
2.0.1 149 9/13/2026
2.0.0 201 7/28/2026
1.0.1 112 7/28/2026
1.0.0 193 7/22/2026