MailChemist 1.0.4

dotnet add package MailChemist --version 1.0.4                
NuGet\Install-Package MailChemist -Version 1.0.4                
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="MailChemist" Version="1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MailChemist --version 1.0.4                
#r "nuget: MailChemist, 1.0.4"                
#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 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 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. 
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.4 981 12/5/2023
0.3.0-beta 1,152 7/5/2020