MindfireTechnology.SimpleEmailRenderer 1.2.6

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

// Install MindfireTechnology.SimpleEmailRenderer as a Cake Tool
#tool nuget:?package=MindfireTechnology.SimpleEmailRenderer&version=1.2.6

Project

This is a very simple email rendering package. Simple dictionary substitution occurrs.

Configuration

  1. Make sure you set the SimpleEmailRenderer:BaseDirectory in your configuration like this:
{
	"SimpleEmailRenderer": {
		"BaseDirectory": "..\\SimpleEmailRenderer\\EmailTemplates"
	},
}
  1. Create a folder in your project called EmailTemplates (or whatever you set the SimpleEmailRenderer:BaseDirectory to)
  2. Each folder in the EmailTemplates folder will be a template. The name of the folder will be the name of the template.
  3. Each template folder should contain a messagebody.html file. This is the template that will be used to render the HTML version of the email.
  4. Each template folder should contain a messagebody.txt file. This is the template that will be used to render the text version of the email.
  5. There should be a settings.json file in the root of the EmailTemplates folder. This file contains the default settings for all templates.
    1. Each template folder may contain a settings.json that override the settings in the root settings.json file.

Example settings.json file:

{
	"FromEmail": "none@none.com",
	"FromDisplayName": "Jon Doe",

	"EmailSubject": "Override Me!"
}

Example settings.json file in a template folder:

{
	"EmailSubject": "This is a template specific subject"
}

The EmailSubject will be "This is a template specific subject" for the template that contains the settings.json file in the template folder. Otherwise the EmailSubject would be set to Override Me!.

Multilingual Configuration

You can add multilingual email templates by using the TwoLetterISOLanguageName as part of the path to the template folder. E.g. BaseDirectory\{TemplateName}\{TwoLetterISOLanguageName}\messagebody.html

Usage

	// This really should be brought in via Dependency Injection (Singleton)
	var renderer = new SimpleEmailRenderer
	{
		BaseDirectory = ".\\EmailDirectory"
	};

	// Here are the values we're going to utilize in our email template:
	var replace = new MergeDictionary
	{ 
		{ "FirstName", "Nate" },
		{ "LastName", "Zaugg" },
		{ "Code", "12345" },
	};

	// Generate the email
	var result = await renderer.GenerateEmail("Welcome", "to@none.com", replace);

	// Send the message
	MailMessage msg = result.ToMailMessage();
	SmtpClient client = new SmtpClient();
	await client.SendMailAsync(msg);

Example of a template:

This file must be named messagebody.html and must be in the folder that matches the template name.

<h2>{{FirstName}} {{LastName}},</h2>

<p>Welcome to our site!</p>

<p>Please use this link to confirm your account: <a href="{{Code}}">{{Code}}</a></p>

Thanks!
Test Email!

A plain text version would be mostly the same, but without the HTML markup, of course. It should be named messagebody.txt and must be in the folder that matches the template name.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  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 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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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.2.6 155 6/13/2023
1.0.0-alpha 302 10/17/2020