Integrate MJML With NodeJS/Express Application

Naveen DA
Oct 19, 2020

--

Integrate MJML With NodeJS/Express Application

Quick Summary

When you working with e-mail content you will know the rendering the e-mail in all mail client is a harder job than writing a JS framework. But MJML takes care of that job and work like a pro.

MJML

https://mjml.io/

https://mjml.io/

This is not an official recommend the process for doing this, but we are using this method for more than 4 years and this work awesome, so I decided to share with the world.

We don’t directly use MJML before sending the mail. We compile the .mjml file and convert into .hbs file so that we can process the mail content with our data.

This is the exact file we use in our app to convert the .mjml into .hbs

We need to run this process after creating the build, so we use postbuild utility scripts to run this.

Our .mjml file looks like this

After the compile and convert into .hbs file, our content look like these

Yeah, definitely it's a huge file but we don’t need to worry about it because mjml will take care of everything like performance, cross-platform compatibility, responsive, etc.

Before sending a mail, we just compile our .hbs via Handlebars

That’s it now your mail can able to render on any e-mail client with proper data

External Links

  1. mjml- https://mjml.io/
  2. handlebars- https://handlebarsjs.com/

Thanks for sticking until the end :)

P.S. 👋 Hi, I’m Naveen DA! If you liked this, consider following me on Twitter and sharing the article with your developer friends 🐋😀

--

--

Naveen DA
Naveen DA

Responses (2)