MindfireTechnology.SimpleEmailRenderer
1.2.6
dotnet add package MindfireTechnology.SimpleEmailRenderer --version 1.2.6
NuGet\Install-Package MindfireTechnology.SimpleEmailRenderer -Version 1.2.6
<PackageReference Include="MindfireTechnology.SimpleEmailRenderer" Version="1.2.6" />
paket add MindfireTechnology.SimpleEmailRenderer --version 1.2.6
#r "nuget: MindfireTechnology.SimpleEmailRenderer, 1.2.6"
// 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
- Make sure you set the
SimpleEmailRenderer:BaseDirectory
in your configuration like this:
{
"SimpleEmailRenderer": {
"BaseDirectory": "..\\SimpleEmailRenderer\\EmailTemplates"
},
}
- Create a folder in your project called
EmailTemplates
(or whatever you set theSimpleEmailRenderer:BaseDirectory
to) - Each folder in the
EmailTemplates
folder will be a template. The name of the folder will be the name of the template. - 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. - 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. - There should be a
settings.json
file in the root of theEmailTemplates
folder. This file contains the default settings for all templates.- Each template folder may contain a
settings.json
that override the settings in the rootsettings.json
file.
- Each template folder may contain a
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 | Versions 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. |
-
.NETStandard 2.1
- Microsoft.Extensions.Configuration.Abstractions (>= 7.0.0)
- System.Text.Json (>= 4.7.2)
-
net5.0
- Microsoft.Extensions.Configuration.Abstractions (>= 7.0.0)
- System.Text.Json (>= 4.7.2)
-
net6.0
- Microsoft.Extensions.Configuration.Abstractions (>= 7.0.0)
- System.Text.Json (>= 4.7.2)
-
net7.0
- Microsoft.Extensions.Configuration.Abstractions (>= 7.0.0)
- System.Text.Json (>= 4.7.2)
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 | 181 | 6/13/2023 |
1.0.0-alpha | 326 | 10/17/2020 |