TPJ.Email 4.0.0

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

// Install TPJ.Email as a Cake Tool
#tool nuget:?package=TPJ.Email&version=4.0.0                

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 net7.0 is compatible.  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 was computed.  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. 
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
4.0.0 338 1/22/2023
3.0.0 1,148 8/20/2017
2.5.0 1,087 5/4/2017
2.3.0 1,325 10/6/2016
2.2.1 1,210 8/30/2016
1.0.0 1,996 4/19/2016

2023 update! V4.0.0 now runs on .NET 7