2.0.0 • Published 10 years ago

derby-email v2.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
10 years ago

Derby Email

Create emails using Derby JS apps/templates. It uses derby-render to render views and juice to inline styles.

Build Status

For convenience, the default results returned match the values read by nodemailer.

Installation

$ npm install derby-email --save

Usage

Create your views:

index.html

<import: src="./other">

<From:>
  {{unescaped $formatEmail('app', 'foo@bar.com')}}

<Body:>
  <p>Some text.</p>

<Text:>
  Some text.

Any view named after a field and capitalized will be returned as a result.

other.html

<Subject:>
  Hello {{user}}

<Body:>
  <p>foo bar</p>

<Text:>
  foo bar

Send your email:

var derby = require('derby');
var app = derby.createApp('app', __filename);
var email = require('derby-email')(app);
var nodemailer = require('nodemailer');
app.loadViews(...);
app.loadStyles(...);

function send(err, emailOptions) {
  var transporter = nodemailer.createTransports(...);
  transporter.send(emailOptions, function (err, info) {
    ...
  })
};

// return email options
email(send);

// with data
var data = {_page: {userId: '...'}};
email(data, send);

// with a specific page (namespace)
email('welcome', send);

// or with both
email('welcome', data, send);

View Functions

The following view functions are available in your views:

$formatEmail(name, address) – Returns a formatted email address. i.e. name <foo@bar.com>.

Options

All options are also passed in to derby-render. See derby-render for a list of options.

fields – The fields (views) to render and return. Includes: html, text, subject, from, to, etc. See Nodemailer for a list of suggested fields.

css – Configuration options passed to inline-css. See inline-csshttps://github.com/jonkemp/inline-css).

2.0.0

10 years ago

1.0.0

10 years ago

0.3.1

11 years ago

0.3.0

11 years ago

0.2.3

11 years ago

0.2.2

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.0

11 years ago