1.1.1 • Published 10 years ago
express-email v1.1.1
Express email
Email solution in node.js.
Render by node-email-templates
Preview by express.js
Send by nodemailler
Usage
var billing_email = require('express-email')(__dirname + '/email/billing');
// preview
if (app.get('env') === 'development') {
var locals = {activation_code: '000000-0000-00000000-000000-00000000'};
app.get('/_mail/billing', billing_email.preview(locals));
}
// render
app.get('/sendBilling', function(req, res, next) {
// ...
var locals = {activation_code: ...};
billing_email.render(locals, function(err, result) {
// result.html
// result.text
// result.attachments
transporter.sendEmail({
from: ...,
to: ...,
subject: ...,
html: result.html,
text: result.text,
attachments: result.attachments
});
});
});API
ExpressEmail(mail_dir, [res_dir])-> EmailEnginemail_dir: see node-email-templatesres_dir: for seaching cid, default:mail_dirEmailEngine#preview(locals)-> Express handlerexample:
app.get('/_email', engine.preview(locals));locals: for render templateIn brower:
get /_email-> email previewEmailEngine#render(locals, callback)locals: for render templatecallback:function(err, result)result.html: html resultresult.text: text resultresult.attachments: attachments for cid
Notice: you can reference cids in your html template, Express email will known it,
and find them in res_dir, and generate result.attachments
Change Logs
- 1.1.0: Preview html and text in one url