-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmailer.js
38 lines (34 loc) · 900 Bytes
/
mailer.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
const nodemailer = require("nodemailer");
const hbs = require("hbs");
const fs = require("fs");
const transport = nodemailer.createTransport({
service: "SendGrid",
auth: {
user: process.env.SEND_USER,
pass: process.env.SEND_PASS
}
});
transport.verify(function(error, success) {
if (error) {
console.log(error);
} else {
console.log("Server is ready to take our messages");
}
});
const generateHTML = (filename, options) => {
const html = hbs.compile(
fs.readFileSync((__dirname, `./views/mails/${filename}.hbs`), "utf-8")
);
return html(options);
};
exports.send = options => {
const html = generateHTML(options.filename, options);
const mailOptions = {
from: "🎃Ironbnb Team 🎃 <noreply@ironbnb.com>",
to: options.email,
subject: options.subject,
message: options.message,
html
};
return transport.sendMail(mailOptions);
};