mjml is a free, open source marketing & customer engagement project written in TypeScript and released under BSD-3-Clause. It has 715 GitHub stars, 251 forks and 35 open issues, and was last pushed 3 months ago. On this registry it ranks #43 of 50 tracked projects in Marketing & Customer Engagement, with 5 head-to-head comparisons available.

What is mjml?

What it is

GrapesJS MJML is a plugin that enables the use of MJML components inside the GrapesJS environment. It lives in the GrapesJS plugin ecosystem and is distributed on npm as grapesjs-mjml. The project is written in TypeScript and released under the BSD-3-Clause license, and it requires GrapesJS v0.15.9 or higher to run.

The concrete problem it solves is authoring responsive email. MJML is a markup language for email, and this plugin brings its components into a visual editor rather than leaving authors to hand-write markup. MJML components are rendered in real time using the official v4 compiler, together with some mocks that let it run in the browser, so the result is almost the same as using the MJML Live Editor. The supported component set covers mj-section, mj-column, mj-text, mj-image, mj-button, mj-social, mj-divider, mj-spacer, mj-hero, mj-navbar, mj-raw, and more, along with head elements such as mj-style and mj-font.

Key capabilities

  • Renders MJML components in real time inside GrapesJS using the official v4 compiler plus browser mocks.
  • Ships blocks for the default MJML component set, selectable through the blocks option.
  • Exports MJML code, with preMjml and postMjml strings to wrap the generated output.
  • Accepts a custom mjmlParser instance from an independent mjml-browser build, so custom or extended MJML components can be added.
  • Supports customComponents to extend the default component list with your own.
  • Provides i18n support through an i18n object, with locale files such as grapesjs-mjml/locale/nl.
  • Resets and configures the environment on init via resetBlocks, resetDevices, resetStyleManager, and hideSelector.

Who uses it and how

  • Newsletter authors who build email layouts visually in GrapesJS and export MJML rather than handwritten HTML.
  • Teams embedding a newsletter builder into an existing GrapesJS instance by adding grapesjs-mjml to the plugins array.
  • Developers with their own MJML build or custom components who override the default parser and register custom GrapesJS components.
  • Multilingual teams that load GrapesJS and plugin locale files together to localize the editor interface.
  • Projects using the import modal with a placeholder template set through importPlaceholder.

Getting started

Install with `npm

project readme (upstream, from github) — read inline

GrapesJS MJML

Requires GrapesJS v0.15.9 or higher

build

This plugin enables the usage of MJML components inside the GrapesJS environment. MJML components are rendered in real-time using the official v4 compiler (+ some mocks to make it run in the browser), therefore the result is, almost, the same as using the MJML Live Editor.

Demo

Supported MJML components (using default mjml-browser parser): mj-mjml mj-head mj-body mj-wrapper mj-group mj-section mj-column mj-text mj-image mj-button mj-social mj-social-element mj-divider mj-spacer mj-style mj-font mj-hero mj-navbar mj-navbar-link mj-raw

Options

Option Description Default
blocks Which blocks to add (all)
block Add custom block options, based on block id. (blockId) => ({})
codeViewerTheme Code viewer theme. hopscotch
customComponents List of components which will be added to default one []
importPlaceholder Placeholder MJML template for the import modal ''
imagePlaceholderSrc Image placeholder source 'https://via.placeholder.com/350x250/78c5d6/fff'
i18n I18n object containing language more info {}
mjmlParser Custom mjml-browser instance. Allows to extend MJML functionality or add custom MJML components (input: string | MJMLJsonObject, opt: MJMLParsingOptions) => MJMLParseResults
overwriteExport Overwrite default export command true
preMjml String before the MJML in export code ''
postMjml String after the MJML in export code ''
resetBlocks Clean all previous blocks if true true
resetDevices Clean all previous devices and set a new one for mobile true
resetStyleManager Reset the Style Manager and add new properties for MJML true
resetDevices Clean all previous devices and set a new one for mobile true
hideSelector Hide the default selector manager true
useXmlParser Experimental: use XML parser instead of HTML. This should allow importing void MJML elements (without closing tags) like `` false
columnsPadding Column padding (this way it's easier to select columns) 10px 0
useCustomTheme Load custom preset theme true

Download

  • npm i grapesjs-mjml

Usage

<link href="path/to/grapes.min.css" rel="stylesheet"/>
<script src="path/to/grapes.min.js"></script>
<script src="path/to/grapesjs-mjml.min.js"></script>

<div id="gjs">
  <mjml>
    <mj-body>
      <!-- Your MJML body here -->
      <mj-section>
        <mj-column>
          <mj-text>My Company</mj-text>
        </mj-column>
      </mj-section>
    </mj-body>
  </mjml>
</div>

<script type="text/javascript">
  const editor = grapesjs.init({
      fromElement: true,
      container: '#gjs',
      plugins: ['grapesjs-mjml'],
      pluginsOpts: {
        'grapesjs-mjml': {/* ...options */}
      }
  });
</script>
Or using ESM imports:
import 'grapesjs/dist/css/grapes.min.css'
import grapesJS from 'grapesjs'
import grapesJSMJML from 'grapesjs-mjml'

grapesJS.init({
   fromElement: true,
   container: '#gjs',
   plugins: [grapesJSMJML],
   pluginsOpts: {
      [grapesJSMJML]: {/* ...options */}
   },
});
i18n usage:
import 'grapesjs/dist/css/grapes.min.css'
import grapesJS from 'grapesjs'
import nl from 'grapesjs/locale/nl'
import grapesJSMJML from 'grapesjs-mjml'
import mjmlNL from 'grapesjs-mjml/locale/nl'

grapesJS.init({
   fromElement: true,
   container: '#gjs',
   i18n: {
      // locale: 'en', // default locale
      // detectLocale: true, // by default, the editor will detect the language
      // localeFallback: 'en', // default fallback
      messages: { nl: nl },
   },
   plugins: [grapesJSMJML],
   pluginsOpts: {
      [grapesJSMJML]: {
        // Optional options
        i18n: { nl: mjmlNL }
      }
   },
});

Using Independent mjml-browser Build

In case, you have your own version of MJML with custom or extended components, it is possible to override default mjml parser with custom one and create custom grapesJS components.

For further info how to create MJML Component, you can visit components folder or you can go to docs.

import 'grapesjs/dist/css/grapes.min.css'
import grapesJS from 'grapesjs'
import grapesJSMJML from 'grapesjs-mjml'
import customMjmlParser from 'custom-mjml-parser';

import customImage from 'custom/components/path'

grapesJS.init({
   fromElement: true,
   container: '#gjs',
   plugins: [grapesJSMJML],
   pluginsOpts: {
      [grapesJSMJML]: {
        mjmlParser: customMjmlParser,
        customComponents: [
          customImage,
        ]
      }
   },
});

Development

Clone the repository

$ git clone https://github.com/GrapesJS/mjml.git
$ cd mjml

Install it

$ npm i

Start the dev server

$ npm start

Releasing

  1. Run npm run v:patch to bump the version in package.json and create a git tag
  2. Push the commit + new tag
  3. Go to github and draft a new release
  4. Select the new tag and add some release notes
  5. Hit publish, the release will automatically publish to npm

License

BSD 3-Clause

Frequently asked questions

Is mjml free to use?

mjml is open source under the BSD-3-Clause licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does mjml do?

Newsletter Builder with MJML components in GrapesJS

What is mjml written in?

mjml is primarily written in TypeScript. Its source is publicly available at https://github.com/GrapesJS/mjml, and it has 715 GitHub stars.