AO.Smtp2Go 1.0.3

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

// Install AO.Smtp2Go as a Cake Tool
#tool nuget:?package=AO.Smtp2Go&version=1.0.3                

This came from a need to send emails with different providers -- Mailgun and Smtp2Go -- leveraging some shared functionality for logging and environment-specific behavior (different behavior for QA vs prod, for example).

I started with a base abstract class MailClientBase, then added implementations for

I offer these as NuGet packages:

In a Nutshell

All mail clients inherit from MailClientBase<TOptions>. Use TOptions to define the settings required for that client. Examples: Mailgun Options, Smtp2Go Options.

For the two email providers in this repo I'm implementing, I overrode the abstract method SendImplementationAsync.

If you want to take advantage of some optional functionality, you'll need to create your own subclass of MailgunClient or Smtp2GoClient. These are the optional overrides:

  • If you want to allow replies to your messages, override GetReplyToAsync. By default, replies are not allowed.
  • If you want logging behavior specific to your application, override LogMessageAsync. Both Mailgun and Smtp2Go log send activity automatically, but you may want to capture outgoing messages in a database table, for example. That's what this is for.

Safe Local and QA Testing

A common requirement with email is you want to make sure QA and local dev environments don't send to production recipients. One reason for this library is that I wanted a definitive solution for this that works with any email provider. I approached this by having a common configuration property OptionsBase.SendMode. All mail client implementations must base their TOptions class on OptionsBase, so they will inherit the SendMode property.

SendMode has 3 options:

  • LogOnly disables all sending, suitable for local dev testing. In this scenario, you'd override LogMessageAsync to capture what would be sent in production. This can still be useful in production (not merely for development) if you want to capture outgoing emails in a database table, for example.
  • Filter allows conditional sending. You would override MailClientBase.FilterMessageAsync to control whether a message sends. You could use this to check for a certain domain, block or allow specific recipients, and so on. Suitable for QA environments or local dev testing. By default, all messages are rejected, so you'll need to override this if you use the Filter send mode.
  • SendAll sends everything, intended as the production setting

When you send a message, the SendMode is checked within method ShouldSendAsync.

Html Email

Html email rendering is a related but separate concern from this. I have a different project RazorToString that addresses this specifically.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 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
1.0.3 450 9/10/2022
1.0.2 396 7/27/2022
1.0.1 448 7/13/2022
1.0.0 427 7/13/2022

Streamlined some internals