Socket
Socket
Sign inDemoInstall

email-templates

Package Overview
Dependencies
Maintainers
2
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

email-templates

Create, preview (browser/iOS Simulator), and send custom email templates for Node.js. Made for Forward Email and Lad.


Version published
Weekly downloads
156K
increased by1.1%
Maintainers
2
Weekly downloads
 
Created

What is email-templates?

The email-templates npm package is a powerful tool for creating, managing, and sending email templates. It supports various templating engines, inline CSS, and internationalization, making it a versatile choice for handling email communications in Node.js applications.

What are email-templates's main functionalities?

Template Rendering

This feature allows you to render email templates with dynamic data. In this example, the 'mars/html' template is rendered with the name 'Elon'.

const Email = require('email-templates');
const email = new Email();

email.render('mars/html', { name: 'Elon' })
  .then(console.log)
  .catch(console.error);

Sending Emails

This feature allows you to send emails using a specified transporter. In this example, an email is sent using Gmail's SMTP service with the 'mars' template and dynamic data.

const Email = require('email-templates');
const nodemailer = require('nodemailer');

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

const email = new Email({
  message: {
    from: 'your-email@gmail.com'
  },
  transport: transporter
});

email.send({
  template: 'mars',
  message: {
    to: 'elon@musk.com'
  },
  locals: {
    name: 'Elon'
  }
}).then(console.log).catch(console.error);

Inline CSS

This feature allows you to inline CSS styles in your email templates. In this example, CSS styles are inlined into the 'mars/html' template.

const Email = require('email-templates');
const email = new Email({
  juice: true,
  juiceResources: {
    preserveImportant: true,
    webResources: {
      relativeTo: path.resolve('path/to/css')
    }
  }
});

email.render('mars/html', { name: 'Elon' })
  .then(console.log)
  .catch(console.error);

Internationalization (i18n)

This feature allows you to support multiple languages in your email templates. In this example, the 'mars/html' template is rendered in French.

const Email = require('email-templates');
const email = new Email({
  i18n: {
    locales: ['en', 'fr'],
    directory: path.join(__dirname, 'locales')
  }
});

email.render('mars/html', { name: 'Elon', locale: 'fr' })
  .then(console.log)
  .catch(console.error);

Other packages similar to email-templates

Keywords

FAQs

Package last updated on 09 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc