1. Products
  2.   Email
  3.   Node.js
  4.   Mailgen
 
  

Opne Source Nodd.js API for Transactional Emails Sending

A Powerful Node.js Transactional Email Processing API enables Software Developers to Create Custom Email Templates & Send HTML or Plain-Text Email Messages inside Node.js Apps.

What is Mailgen Librarys?

Effective communication is a cornerstone of any successful application, whether it’s sending transactional emails, welcome messages, or newsletters. For software developers aiming to craft visually appealing and professional email templates without extensive design expertise, the Mailgen library offers an elegant solution. It is an open-source library developed by Elad Nava, a seasoned developer and entrepreneur. The library uses a template-based approach, which means you can create custom email templates using your preferred format (Markdown, HTML, or JSON). This makes it easy to customize the look and feel of your emails without requiring extensive HTML knowledge.

Mailgen is very easy to handle and makes it easy for software developers to create visually appealing HTML and plain-text emails inside Node.js applications. Its ease of use, flexibility, and open-source nature make it a favorite among developers.With Mailgen, you can customize every aspect of your email, from the layout to the content. You can add or remove sections, add images or photos, change the font, color scheme, and more with little effort. The library provides a simple and intuitive way to generate emails using a template-based approach. It supports dual-format emails, offering both HTML for visually rich emails and plain text for simpler email clients.

Previous Next

Getting Started with Mailgen

The recommend way to install Mailgen is using NPM. Please use the following command for a smooth installation.

Install Mailgen via npm

npm install mailgen --save
 

Create Email by Rendering Template in Node.js

The open source Mailgen library allows software developers to create customize email templates inside node.js applications. It supports creating a template using user’s preferred format (Markdown, HTML, or JSON). The following example demonstrates how to use the render method and a simple Markdown template to render your template with the desired data and send the email message inside Android applications.

How to Render the Template to Create Email Messages inside Android?

 
const mailgen = require('mailgen');

const template = mailgen({
  theme: 'clean',
  subject: 'Welcome to [App Name]!',
  message: 'Hello {{ name }}, Welcome to [App Name]! We\'re thrilled to have you on board.',
  from: 'hello@app.com',
  to: 'john.doe@example.com',
  name: 'John Doe'
});
const email = template.render();
console.log(email);

 

Create HTML and Plain-Text Emails in Node.js

The Mailgen library enables software developers to generate email messages in both HTML and plain-text formats with just a couple of lines of code inside Node.js applications. It ensures compatibility across all email clients, even those that don't render HTML. Here is an example that shows how software developers can send an email message in HTML format as well as in plain-text format inside Node.js environment.

How to Create HTML and Plain-Text Email Messages inside Android Apps?

 
const emailBodyHtml = mailGenerator.generate(emailContent);
const emailBodyText = mailGenerator.generatePlaintext(emailContent);

console.log(emailBodyHtml);  // HTML version
console.log(emailBodyText);  // Plain-text version

 

Send Email Messages inside Node.js

The open source Mailgen packages allows software developers to send email message using their preferred email-sending library to dispatch the email. Mailgen works seamlessly with popular Node.js email-sending libraries like Nodemailer, enabling smooth integration into existing applications. For the following example we are using the Nodemailer library to send an email message.

How to Send Email message inside Node.js Apps?

 
const nodemailer = require('nodemailer');  
const transporter = nodemailer.createTransport({  
    service: 'gmail',  
    auth: {  
        user: 'your-email@gmail.com',  
        pass: 'your-email-password'  
    }  
});  

const mailOptions = {  
    from: 'no-reply@yourapp.com',  
    to: 'john.doe@example.com',  
    subject: 'Welcome to Your App',  
    html: emailBodyHtml,  
    text: emailBodyText  
};  

transporter.sendMail(mailOptions, (error, info) => {  
    if (error) {  
        return console.error(error);  
    }  
    console.log('Email sent: ' + info.response);  
});  
 

Customization and Extensibility

The open source Mailgen library comes with pre-designed templates and is also highly customizable. Software developers can modify existing themes or create their own by adjusting the layout, colors, and branding elements. The package also allows users to configure their own custom CSS and adjust the content structure according to your needs.