/
index.js
48 lines (37 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import nodemailer from 'nodemailer';
import config from '../../config';
import templates from './templates';
import juice from 'juice';
// library configuration ---------------------------------------
// setup email transporter
var transporter = nodemailer.createTransport({
service: config.notifications.email.service,
auth: {
user: config.notifications.email.user,
pass: config.notifications.email.pass
}
});
// public api --------------------------------------------------
export default {
/**
* Send
*
* Takes an email address, a subject, a template name
* and a data object and immediately sends an email.
*/
send (email, callback) {
// template data
let html = templates[email.template](email.data);
// inline styles
html = juice(html);
// configure mail options
var mailOptions = {
from: config.notifications.email.user,
to: email.to,
subject: email.subject,
html: html
};
// send email
transporter.sendMail(mailOptions, callback);
}
};