TPJ.Email 10.0.0

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

TPJ.Email

Simple SMTP email library for .NET that supports HTML emails, attachments, single sends, and batch sends.

Install

dotnet add package TPJ.Email

Configuration

Add your SMTP settings to appsettings.json.

{
  "TPJ": {
    "Email": {
      "SmtpClient": "smtp.example.com",
      "SmtpUser": "smtp-user",
      "SmtpPassword": "smtp-password",
      "From": "no-reply@example.com",
      "FromDisplayName": "My App",
      "Port": 587,
      "EnableSSL": true,
      "Debug": false
    }
  }
}

Supported settings:

  • SmtpClient
  • SmtpUser
  • SmtpPassword
  • From
  • FromDisplayName
  • Port
  • EnableSSL
  • Debug

SmtpClient, SmtpUser, and SmtpPassword can also be loaded from Azure Key Vault by using:

  • TPJ:Email:AzureKeyVault:SmtpClient
  • TPJ:Email:AzureKeyVault:SmtpUser
  • TPJ:Email:AzureKeyVault:SmtpPassword

Register the package

Register IEmailSettings from configuration, then add the email services.

using TPJ.Email;

builder.Services.AddTPJEmail();

Console app example

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TPJ.Email;

var configuration = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("appsettings.json", optional: false)
    .Build();

var services = new ServiceCollection();
services.AddTPJEmail();

using var serviceProvider = services.BuildServiceProvider();

var emailer = serviceProvider.GetRequiredService<IEmailer>();

await emailer.SendAsync(new CreateEmailSingle
{
    To =
    [
        new CreateEmailAudience
        {
            Email = "jane@example.com",
            DisplayName = "Jane"
        }
    ],
    Subject = "Hello from a console app",
    Body = "<h1>Email sent from TPJ.Email</h1><p>This email was sent from a console application.</p>"
});

API example

Example with a minimal API:

using TPJ.Email;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSingleton<IEmailSettings>(_ => new EmailSettings(builder.Configuration));
builder.Services.AddTPJEmail();

var app = builder.Build();

app.MapPost("/emails/test", async (string to, IEmailer emailer, CancellationToken cancellationToken) =>
{
    await emailer.SendAsync(new CreateEmailSingle
    {
        To =
        [
            new CreateEmailAudience
            {
                Email = to
            }
        ],
        Subject = "Hello from the API",
        Body = "<p>This email was sent from an ASP.NET Core API.</p>"
    }, cancellationToken);

    return Results.Accepted();
});

app.Run();

Batch email example

Use SendBatchAsync when you want to send the same base email to multiple recipients, with optional per-recipient subject or body overrides.

await emailer.SendBatchAsync(new CreateEmailBatch
{
    From = new CreateEmailAudience
    {
        Email = "no-reply@example.com",
        DisplayName = "My App"
    },
    Subject = "Weekly update",
    Body = "<p>Default email body</p>",
    Emails =
    [
        new CreateEmailEmail
        {
            To =
            [
                new CreateEmailAudience { Email = "alice@example.com", DisplayName = "Alice" }
            ]
        },
        new CreateEmailEmail
        {
            To =
            [
                new CreateEmailAudience { Email = "bob@example.com", DisplayName = "Bob" }
            ],
            Subject = "Weekly update for Bob",
            Body = "<p>Custom body for Bob</p>"
        }
    ]
});

Attachments

Attachments can be added by file path or byte array.

await emailer.SendAsync(new CreateEmailSingle
{
    To =
    [
        new CreateEmailAudience { Email = "jane@example.com" }
    ],
    Subject = "Report",
    Body = "<p>Please find the report attached.</p>",
    Attachments =
    [
        new CreateEmailAttachment
        {
            FilePath = "Reports/report.pdf"
        }
    ]
});

Notes

  • Email bodies are sent as HTML.
  • If From is omitted on the email request, the configured TPJ:Email:From value is used.
  • Each CreateEmailEmail in a batch is sent separately.
  • To must contain at least one valid email address.
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. 
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 TPJ.Email:

Package Downloads
TPJ.Logging

Simple error logging library that can send emails and/or log to a txt file

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.0 114 5/9/2026
9.0.0 531 12/18/2024
4.0.0 762 1/22/2023
3.0.0 1,997 8/20/2017
2.5.0 1,936 5/4/2017
2.3.0 2,512 10/6/2016
2.2.1 2,214 8/30/2016
1.0.0 3,672 4/19/2016

V10.0.0 now runs on .NET 10 with significant changes to how emails are sent see README.md for details