AO.Smtp2Go
1.0.2
See the version list below for details.
dotnet add package AO.Smtp2Go --version 1.0.2
NuGet\Install-Package AO.Smtp2Go -Version 1.0.2
<PackageReference Include="AO.Smtp2Go" Version="1.0.2" />
paket add AO.Smtp2Go --version 1.0.2
#r "nuget: AO.Smtp2Go, 1.0.2"
// Install AO.Smtp2Go as a Cake Addin #addin nuget:?package=AO.Smtp2Go&version=1.0.2 // Install AO.Smtp2Go as a Cake Tool #tool nuget:?package=AO.Smtp2Go&version=1.0.2
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 overrideLogMessageAsync
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 theFilter
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 | Versions 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. |
-
net6.0
- Microsoft.Extensions.Http (>= 6.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.1)
- Microsoft.Extensions.Options (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.