Code Monkey home page Code Monkey logo

mailchemist's Introduction

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 MailChemistEngine(MailChemistMjmlRenderer.MjmlDotNet);
mailChemist.Render(content, model);

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 Render() or RenderFluid().

Usage using file content provider

If you want a higher performance by using already Generated MJML you can use the FileContentProvider without the overhead of connecting to an external website to Generate the MJML.

var contentProvider = new FileContentProvider("Email\\Assets");
var mailChemistEngine = new MailChemistEngine(MailChemistMjmlRenderer.MjmlDotNet, contentProvider)

mailChemist.Render(content, model);

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.RegisterGlobalFilter().

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:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.