expresser-mailer
Email sending plugin for Expresser.
Last updated a year ago by igoramadas .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install expresser-mailer 
SYNC missed versions from official npm registry.

Expresser Mailer

Before you start make sure you have set the main SMTP server details on settings.mailer.smtp and settings.mailer.from with a default "from" email address. An optional secondary can be also set on settings.mailer.smtp2, and will be used only in case the main server fails.

The template handler expects a base template called "base.html", with a keyword "{contents}" where the email contents should go.

If settings.app.cloud is true, the Mailer module will automatically figure out the SMTP details for the following email services: Mailgun, Mandrill, SendGrid.

Sample code

The example below shows how to load the "login.html" template, parse and update the keywords {user} and {registrationDate} with igor and with the current date, and send a login confirmation email. The "from" address will be the default "from" address set on the settings.

var expresser = require("expresser");
var template = expresser.mailer.getTemplate("login");
var keywords = {username: "igor", registrationDate: new Date()}
var loginMessage = expresser.mailer.parseTemplate(template, keywords);

// getting the template manually to set the email body:
expresser.mailer.send({body: loginMessage, subject: "Login confirmation", to: "mailto@igor.com"});

// alternate method to use templates directly via options:
expresser.mailer.send({keywords: keywords, template: "login", subject: "Login confirmation", to: "mailto@igor.com"});

Please note that you can also use a different SMTP transport server if needed, by creating your own SMTP transport object using the "createSmtp" helper. It accepts the same options as the ones set under settings.mailer.smtp. Example below:

var customSmtp = expresser.mailer.createSmtp({
    host: "my.smtp.com",
    port: "587"
})

expresser.mailer.send({subject: "Login confirmation", to: "mailto@igor.com", smtp: customSmtp});

The Mailer module is a wrapper around Nodemailer, so some of its features can be used directly. The default SMTP transport objects are exposed as "smtp" and "smtp2". More info at [http://www.nodemailer.com].

For detailed info on specific features, check the annotated source on /docs folder.

Current Tags

  • 3.1.1                                ...           latest (a year ago)

14 Versions

  • 3.1.1                                ...           a year ago
  • 3.1.0                                ...           2 years ago
  • 3.0.5                                ...           2 years ago
  • 3.0.4                                ...           3 years ago
  • 3.0.3                                ...           3 years ago
  • 3.0.2                                ...           3 years ago
  • 3.0.1                                ...           3 years ago
  • 3.0.0                                ...           3 years ago
  • 1.2.1                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.0                                ...           5 years ago
  • 1.0.0-alpha.1                                ...           5 years ago
Maintainers (1)
Downloads
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 1
Last Month 4
Dependencies (2)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |