Email Transporter
A simple email transporter that utilizes nodemailer and email-template module.
const path = require('path');
const nodemail = require('email-transporter')({
agent: require('nodemailer'),
config: require('../config/main.js').smtp,
template: require('email-templates').EmailTemplate
});
const EmailTemplate = require('email-templates').EmailTemplate;
function sendInvitationEmail(options, body) {
const templateDir = path.join(__dirname, '..', 'template', 'invite')
return nodemail.template({
dir: templateDir,
data: {
name: body.name,
surname: body.surname,
id: body.id,
},
from: options.from,
to: options.to,
subject: options.subject,
});
}
module.exports = {
send: sendInvitationEmail
}
app.get('/invite', (req, res) => {
const to = 'alexander.hongpin@gmail.com';
emailClient.send({
from: '"Fred Foo 👥" <foo@blurdybloop.com>',
to: to,
subject: 'Join us now!',
}, {
name: 'john',
surname: 'doe',
id: 'X07569'
}).then((response) => {
if (response) {
res.status(200).json({
data: 'successfull sent the email to ' + to
});
}
});
});