0.0.2 • Published 11 years ago
peryton v0.0.2
peryton
A simple API to send emails formatted with various templating libs.
This module also wraps nodemailer, making e-mail sending easy.
Templating engines
The following templating engines are supported. The dependencies listed are required in order to run them along with this library.
- swig,
npm install swig --save
, https://github.com/paularmstrong/swig/ - jade,
npm install jade --save
, https://github.com/visionmedia/jade
API
swig
The following example illustrates how to use peryton
with swig
template engine.
For swig
it's also possible to define custom filters:
var Email = require('peryton'),
email = Email.create({
// route to your template file
template: 'file.html',
// before you can send any e-mails you need to set up a transport method
transport: Email.Transport({
service: 'Gmail',
auth: {
username: "username@gmail.com",
password: "yourpassword"
}
}),
// use swig
engine: Email.Swig({
config: {
cache: process.env['NODE_ENV'] === 'production' ? 'memory' : false,
},
// define custom filters
filters: {
smurf: function(str){
return str.replace(/\w+/g,'smurf')
}
}
}),
});
email.send( to, from, subject, locals, function( err, email ){
// return callback gets two parameters: err, mail
});
jade
In the case of jade
, you will need to define your mixins:
engine: Email.Jade({
config: {
cache: process.env['NODE_ENV'] === 'production' ? 'memory' : false,
},
// define custom mixins
mixins: {
smurf: function(str){
return str.replace(/\w+/g,'smurf')
}
}
})
Install
The source is available for download from GitHub. Alternatively, you can install using Node Package Manager (npm):
npm install peryton --save