MailChemist 1.0.4
dotnet add package MailChemist --version 1.0.4
NuGet\Install-Package MailChemist -Version 1.0.4
<PackageReference Include="MailChemist" Version="1.0.4" />
paket add MailChemist --version 1.0.4
#r "nuget: MailChemist, 1.0.4"
// Install MailChemist as a Cake Addin #addin nuget:?package=MailChemist&version=1.0.4 // Install MailChemist as a Cake Tool #tool nuget:?package=MailChemist&version=1.0.4
MailChemist
MailChemist is a combination of two technologies (MJML, and Fluid.NET) to dynamically generate beautiful responsive emails driven by templates.
Content Providers
An email content provider is a high-level class that handles preparing the email template content for fluid Generater using e.g. Web API, file and SQL. Currently MailChemist supports two content providers:
- MJML API
- File
Getting started
Basic usage example
Basic usage using the MJML API and Fluid using an anonymous model.
var model = new
{
FirstName = "Paul"
};
string content = @"<mjml><mj-body>{{ Model.FirstName }}</mj-body></mjml>";
var mailChemist = new MailChemist("YourMjmlAppId", "YourMjmlSecretKey");
mailChemist.TryGenerate(content, model, out var result, out var errors, true);
RegisterType is required to be set to true since it's an anonymous type. This should be set to false, if you intend on using the
MailChemistModel
attribute which would be cached.
Usage without having to register the type each call
[MailChemistModel]
public class PersonModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
If your using nested types, you will need to decorate them with
MailChemistModel
too.
You will only need to call MailChemist.RegisterGlobalTypes()
once before calling TryGenerateFluid()
or TryGenerate()
.
Usage using file content provider
If you want a higher performance by using already Generated MJML you can use the FileEmailContentProvider
without the overhead of connecting to an external website to Generate the MJML.
var mailChemist = new MailChemist(new FileEmailContentProvider("Templates"));
mailChemist.TryGenerate("Test.mc", model, out var result, out var errors, true);
Test.mc
would contain the pre-Generated MJML with Fluid.NET templating.
Fluid.NET Filters
MailChemist utilises Fluid.NET under the hood because of this; You can leverage custom filter functions in your templates. MailChemist has out of the box fluid filters which can be registered by running MailChemist.RegisterGlobalFilters()
.
IsLessThanZeroAddClassFilter
IsLessThanZeroAddClassFilter
can be used like:
<div class="{{ Model.Profit | IsLessThanZeroAddClass:'redText' }}">{{ Model.Profit }}</div>
If Profit
was lower than zero then it would generate:
<div class="redText">-1</div>
Appreciations
Thanks to the following great projects that made MailChemist possible:
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 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. |
-
net6.0
- Fluid.Core (>= 2.5.0)
- MailChemist.Core (>= 1.0.3)
- Mjml.Net (>= 3.1.0)
- Newtonsoft.Json (>= 13.0.3)
-
net7.0
- Fluid.Core (>= 2.5.0)
- MailChemist.Core (>= 1.0.3)
- Mjml.Net (>= 3.0.0)
- Newtonsoft.Json (>= 13.0.3)
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.4 | 889 | 12/5/2023 |
0.3.0-beta | 1,150 | 7/5/2020 |