Legendary Emails in Node js with mjml 📩

Sometimes I receive emails from various companies and start-ups that look very attractive and audience-friendly. 😶‍🌫️

In their emails, they used a unique font along with images and buttons. What stood out the most was how their email format was respon…


This content originally appeared on DEV Community and was authored by Ali.t.nazari

Sometimes I receive emails from various companies and start-ups that look very attractive and audience-friendly. 😶‍🌫️

In their emails, they used a unique font along with images and buttons. What stood out the most was how their email format was responsive, adapting well to different devices.

After seeing the emails, I decided to send similar emails to users for the store project I was developing 😎

you can check it out if you like from the link below:
https://github.com/Silent-Watcher/express-shop

Anyway, I stumbled upon a tool called MJML that could be used to implement this feature.

As stated in its documentation:

MJML is a markup language designed to reduce the pain of coding a responsive email.

As developers, we don't have to be involved in complex responsive email designs but you can spend some time learning the syntax if you’d like.

Good news for Node.js developers: MJML is coded in Node.js. However, if you use other languages such as Python, you can utilize the MJML API.

For more information, you can refer to this post on the Medium website

To begin, we will need to install two packages: eta and mjml.

bun add eta@latest mjml@latest

After that, I created a file named mail.tpl.js where we initialize MJML and ETA to create our email template.

mjml

The template I used is the hello world template from the MJML documentation, which looks something like this

mjml email preview

After accessing your email template in HTML format, if you are using *Nodemailer * for sending emails, you can create a ‘sendmail’ function that can be utilized later in the project

To achieve this, I created a file named ‘mailer.js’ and initialized the Nodemailer package:

Nodemailer

Now, you can utilize this function wherever you wish to send emails. To define your template, simply use the ‘html’ option within the first parameter.

send mail in node js

that’s pretty much it. let me know what you think. 🤗


This content originally appeared on DEV Community and was authored by Ali.t.nazari


Print Share Comment Cite Upload Translate Updates
APA

Ali.t.nazari | Sciencx (2024-06-30T19:55:36+00:00) Legendary Emails in Node js with mjml 📩. Retrieved from https://www.scien.cx/2024/06/30/legendary-emails-in-node-js-with-mjml-%f0%9f%93%a9/

MLA
" » Legendary Emails in Node js with mjml 📩." Ali.t.nazari | Sciencx - Sunday June 30, 2024, https://www.scien.cx/2024/06/30/legendary-emails-in-node-js-with-mjml-%f0%9f%93%a9/
HARVARD
Ali.t.nazari | Sciencx Sunday June 30, 2024 » Legendary Emails in Node js with mjml 📩., viewed ,<https://www.scien.cx/2024/06/30/legendary-emails-in-node-js-with-mjml-%f0%9f%93%a9/>
VANCOUVER
Ali.t.nazari | Sciencx - » Legendary Emails in Node js with mjml 📩. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/06/30/legendary-emails-in-node-js-with-mjml-%f0%9f%93%a9/
CHICAGO
" » Legendary Emails in Node js with mjml 📩." Ali.t.nazari | Sciencx - Accessed . https://www.scien.cx/2024/06/30/legendary-emails-in-node-js-with-mjml-%f0%9f%93%a9/
IEEE
" » Legendary Emails in Node js with mjml 📩." Ali.t.nazari | Sciencx [Online]. Available: https://www.scien.cx/2024/06/30/legendary-emails-in-node-js-with-mjml-%f0%9f%93%a9/. [Accessed: ]
rf:citation
» Legendary Emails in Node js with mjml 📩 | Ali.t.nazari | Sciencx | https://www.scien.cx/2024/06/30/legendary-emails-in-node-js-with-mjml-%f0%9f%93%a9/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.