html-mailer
small library for sending emails rendered from html files
Last updated 2 years ago by dpineda .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install html-mailer 
SYNC missed versions from official npm registry.

html-mailer ยท npm version

html-mailer is a small library that allows you to send rendered emails from HTML files with the insertion of variables within the templates to add dynamism.

Install

npm install --save html-mailer

Usage

The first step is to create a folder in the root of the project called views, within this folder the html templates, can contain sub folders.

Configuration and send Email
// Email acount to send emails
const config = {
  host: 'your_smtp_server',
  port: 465,
  secure: true,
  auth: {
    user: 'your_email_address@your_domain.com',
    pass: 'your_email_passoword'
  }
}

const htmlMailer = require('html-mailer')(config);

// variables that are entered in the template
const EMAIL_VARS = {
  x: 'info for var x',
  ...
};

const NAME = 'my mame'; // senders name
const FROM_ADDRESS = 'from_address@gmail.com'; // senders email address
const TO_ADDRESS = 'to_address@hotmail.com'; // receiver email address
const SUBJECT = 'test'; // subject of email
const RELATIVE_TEMPLATE_PATH = 'emails/contact'; // relative path of the html file with the content of the email

// Send email
htmlMailer.sendEmail(RELATIVE_TEMPLATE_PATH, EMAIL_VARS, NAME, FROM_ADDRESS, TO_ADDRESS, SUBJECT, (err, response) => {
  if (err) {
    console.log('Error sending mail', err)
  } else {
    console.log('Message sent correctly')
  }
});
Html template example
<!-- html template with variables embed - remember put the templates in views folder -->
<html>
  <head></head>
  <body>
    <div style="width: 80%; margin: 0 auto; text-align: center">
      <h2>My var X</h2>
      <p>#{x}</p>
    </div>
  </body>
</html>

dependencies

This library currently has 3 dependencies

Current Tags

  • 1.0.2                                ...           latest (2 years ago)

3 Versions

  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (3)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |