Mistware.Postman 1.0.0

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

// Install Mistware.Postman as a Cake Tool
#tool nuget:?package=Mistware.Postman&version=1.0.0

This Mail Merge Engine enables a web app to quickly construct a list of emails to send, and then have this list processed as a background thread. It uses SendGrid to send the emails. Each email has a plain text body, and an optional attachment. The subject and body of each email is generated from a template.

Emails are sent as batch of related emails from one sender. Each email batch consists of:

  1. Name - the name of the batch.
  2. From - the person sending the batch (email address and name).
  3. Postmaster - the email to be used as the sending address (email address and name).
  4. Recipients - a list of email recipients (see next).

It is typically the case that Postman (i.e. SendGrid) is used outside an internal company network. In that case emails cannot be sent from the sender (From email address and name), because those emails will be blocked by the company's firewall / mail gateway (which quite rationally rejects external emails with an internal domain). Instead emails must be sent from a fictitious 'Postmaster' email address (which has a domain outside the company domain).

Each email recipient consists of:

  1. To - a recipient (email address and name).
  2. DeliveryType - delivery type - a code the selects the respective template.
  3. MailMergeFields - a dictionary of parameters to substitute into the template.
  4. Attachment - the filename of an optional attachment (if the filename is null, then no attachment is sent).

The templates are stored in a single file, where each tempate is identfied by a code (delivery type), for example the XYZ template:

%%XYZ-Subject
The email subject line goes here with a  : {Reference}
%%XYZ-Body
Please find attached a summary of the ACME Corporation report:

Report Number : {Reference}

Title : {Title}

Author : {Author}

{Summary}

%%ABC-Subject
etc ...

Other templates (e.g. the ABC template) follow in the same file. Templates come in pairs (e.g. XYZ-Subject and XYZ-Body). The double percentage ("%%") is the delimiter indicating the start of the next template. Each template field (e.g. {Reference}) must be a key in the dictionary. For example this template expects the keys: Reference, Title, Author and Summary. If any keys are omitted then the email is sent, but the field is not replaced with a value.

Attachments are obtained using a Mistware.Files file system (either local or an Azure File Share). If no attachments are to be sent, then the file system can be left uninitialised (though the dependency of Mistware.Files will remain). In addition to setting up the file system, it is also necessary to change to the directory on the file system that contains the files to be attached. Each attachment's filename is specified with the recipient, though it is anticpated that a batch will typically send just one attachment (e.g. one report). This makes it possible to send a mixture of emails, some with and some without attachments, in the same batch.

The classes are:

  • MailEngine - the core of this package, which exposes: a property that must be set (SendGridKey), a property that must be set if attachments are to be sent (FileSys), a method to load the templates and a method to send a list of batches.
  • EmailBatch - the definition of each email batch
  • EMailRecipient - the definition of each recipient

Other classes are internal to the package and can be ignored (including SendMail, which is an interface to the SendGrid package).

Usage

To add the nuget package to a .Net Core application:

dotnet add package Mistware.Postman

Dependences include the following packages: Mistware.Utils, Mistware.Files and SendGrid.

All that is needed to use the mail engine is to create the list of EmailBatch (including a list of EmailRecipient, each with a dictionary of template or mail merge fields). And then to call the following:

IFile filesys = FileBootstrap.SetupFileSys(connection, container, root, logs);
filesys.ChangeDirectory(folder);

MailEngine engine = new MailEngine();
engine.SendGridKey = key; // SendGrid API key from configuration
engine.FileSys = filesys;
engine.LoadTemplates(path, filename);
engine.Start(batches); // where batches is List<EmailBatch>

See Mistware.Files documentation on the use of FileBootstrap and ChangeDirectory.

Mistware.Postman uses the logging provided by Mistware.Utils and Mistware.Files (see their respective documentation). Either a rolling file log on local file storage or logging on Azure BLOB storage. FileBootstrap will setup the logging as well as the file system.

Testing

Mistware.Postman has a basic test program in the test folder (MistwarePostmanTest.csproj), which is in itself an example of how to use this package.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.0 545 5/6/2020