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.
The template I used is the hello world template from the MJML documentation, which looks something like this
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:
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.
thatβs pretty much it. let me know what you think. π€
Top comments (16)
by the way the MJML stands for *mailjet markup language * πΆπ»ββοΈ
i'll file this away for my next project... thanks for the article
I've used MJML in the past. It's effectively my go-to for beautiful emails both for campaigns and transactional emails (ie password resets, verification, etc)
That's great to hear! MJML is definitely a powerful tool for creating visually appealing emails.
I think this is awesome, man. Can anyone write a post outlining how to use SMTPS (custom domain emails with Nodemailer)?
Kindly for anyone who achieved this show up , I'll appreciate π¦Ύ
Hi,
thank you for sharing and writing this article.
I was just curios, why not use some mail template providers to begin with?
Like SendGrid or MailJet
Thanks again!
Impressive. Innovant.
Thank you for your positive feedback! π€
MJML is an excellent resource for mailing. That is why I put it in default in Framework X. Check it out.
I'm using this in my work, it's awesome.
Is it free and integrate google's smtp for personal email use case testing?
I can be interested can it be used with PHP Laravel
I think it can be used for any email services and to integrate MJML into your PHP app, you have to use its API.
happy coding ! π€
thanks for sharing.. im glad to reach your posting.
You're welcome! I'm glad you found it helpful.