punch-emailer
v0.0.1
Published
Module for send emails based on nodemailer.
Downloads
1
Readme
punch-emailer
Send emails
Config
- from - email address that used to send emails
- templateDir - dir with email templates
- nodemailerConf - nodeemail config see https://github.com/nodemailer/nodemailer
- logger - function that can log sent emails (example - console.log)
Templates
see email-templates documentation https://github.com/niftylettuce/node-email-templates
<div>
Hello, <%= user.firstName + ' ' + user.lastName %>
Reset password link <a href="<%- verificationLink %>" target="_blank">link</a>
Or just copy the link: <%- verificationLink %>
</div>
Usage
'use strict';
const PunchEmailer = require('punch-emailer');
const path = require('path');
const smtpConfig = {
host: process.env.SMTP_HOST || 'xxxxx',
port: process.env.SMTP_PORT || 465,
secure: process.env.SMTP_SECURE || true, // use SSL
auth: {
user: process.env.SMTP_USER || 'xxxxx',
pass: process.env.SMTP_PASS || 'xxxxx'
}
};
const HOST = process.env.HOST || ' http://xxxxx.com/';
const querystring = require("querystring");
const templateDir = path.join(__dirname, 'templates');
const config = {
from: process.env.SMTP_FROM || '[email protected]',
templateDir: templateDir,
nodemailerConf : smtpConfig
};
class Emailer extends PunchEmailer {
sendEmailVerification(to, data){
let queryParams = querystring.stringify({email : to, code : data.verificationCode});
data.verificationLink = HOST + '#/confirm-email?' + queryParams;
return this.sendTemplate(
to,
'Email verification',
'email-verification',
data
);
};
sendResetPassword(to, data){
let queryParams = querystring.stringify({email : to, code : data.verificationCode});
data.verificationLink = HOST + '#/reset-password?' + queryParams;
return this.sendTemplate(
to,
'Reset password',
'reset-password',
data
);
};
};
module.exports = new Emailer(config);
const emailer = require('./emailer');
emailer.sendEmailVerification('[email protected]', {
user : {
firstName : 'Jastin',
lastName : 'Hastin'
},
verificationCode : 'xxx-xxx-xxxx'
})