TPJ.Email 9.0.0

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

TPJ.Email

Simple email library that can send html and attachments

Configuration

For most cases you'll be using DI to setup the email configuration but you can simple create a new Emailer object and pass in a EmailSettings with your config if you require

var emailer = new Emailer(new EmailSettings() {
... your settings...
});

emailer.Send(...);

For the normal DI setup open your appsettings.json and add a TPJ → Email section, within this you need to configure some settings

Required:

  • SmtpClient - SMTP server which e-mails will be sent from e.g. smtp.gmail.com
  • From - e-mails are sent from this account (can be overridden when sending in code)

Optional:

  • SmtpUser - Send e-mail authing with the given user name
  • SmtpPassword - Send e-mail authing with the given password
  • FromDisplayName - e-mails are sent with this value as the display name (can be overridden when sending in code)
  • EnableSSL - Use SSL when sending the e-mail
  • Port - Port to send from e.g. 587 (SSL port)
{
  "TPJ": {
    "Email": {
      "SmtpClient": "smtp.gmail.com",
      "SmtpUser": "",
      "SmtpPassword": "",
      "From": "",
      "FromDisplayName": "Test Display Name",
      "EnableSSL": true,
      "Port": 587
    }
  }
}

Now within your Startup method call services.AddTPJEmail(); now you can inject TPJ.IEmailer. See github for an example for both a console and API using DI.

Simple Console App

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

namespace TPJ.EmailTest;

class Program
{
    private static IEmailer _emailer = default!;

    static async Task Main(string[] args)
    {
        SetUp();

        _emailer.Send("test@test.com", "Test TPJ Email", "<h1>This is a test sent from a console app</h1>", true);
    }

    private static void SetUp()
    {
        var builder = new ConfigurationBuilder()
              .SetBasePath(System.IO.Directory.GetCurrentDirectory())
              .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);

        var configuration = builder.Build();

        var services = new ServiceCollection();

        services.AddSingleton<IConfiguration>(configuration);
        services.AddTPJEmail();

        var serviceProvider = services.BuildServiceProvider();

        _emailer = serviceProvider.GetRequiredService<IEmailer>();
    }
}
Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.0.0 355 12/18/2024
4.0.0 612 1/22/2023
3.0.0 1,840 8/20/2017
2.5.0 1,779 5/4/2017
2.3.0 2,354 10/6/2016
2.2.1 2,052 8/30/2016
1.0.0 3,515 4/19/2016

V9.0.0 now runs on .NET 9