#NodeMailer
###An easy to use nodejs mailing library with integration for different templates
npm install --save nicemail
Requirements
- Node.js >= 6.11.0
- ECMAScript >= 6
Usage
const Nicemail = require('nicemail');
const path = require('path');
const emailConfig = {
sender: 'Sender <abc@company.com>',
host: 'smtp.gmail.com',
port: '465',
auth: {
user: '',
pass: ''
}
};
const templateConfig = {
dir: path.join(__dirname,'./template') ,
type: 'hbs'
}
const nm = new Nicemail(emailConfig, templateConfig);
const receipents = ['abc@gmail.com','bcd@gmail.com'];
nm
.send({
template: 'simple',
subject: 'Simple subject text',
content: {
title : 'This is title',
header : 'This is header',
body : 'Body Message'
},
to : receipents.join(',')
})
.then(res => console.log('Response: ', res))
.catch(err => console.log('Errors: ', err));
templates/simple.hbs:
<div>
{{ title }}
<h6>{{ header }}</h6>
<p>{{ body }}</p>
</div>
####Other templates
templates/simple.pug:
.div
#{ title }
h6 #{ header }
p #{ body }
templates/simple.ejs:
<div>
<%= title %>
<h6><%= header %></h6>
<p><%= body %></p>
</div>