-
Notifications
You must be signed in to change notification settings - Fork 242
/
Copy pathmailer.js
32 lines (30 loc) · 1.18 KB
/
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
let SystemOptions = require("../models/system-options");
let transporter = require("../config/transporter");
let _ = require("lodash");
let sendMail = function (address, message, subject) {
SystemOptions.findAll(undefined, undefined, function (result) {
let company_email = result.filter(option => {
return option.data.option == 'company_email'
})[0].get("value");
let company_name = result.filter(option => {
return option.data.option == 'company_name'
})[0].get("value");
let mailOptions = {
from: `"${company_name}" <${company_email}>`, // sender address
to: address, // list of receivers
subject: subject, // Subject line
html: message, // html body
text: message // text only body
};
console.log("MAILING!");
console.log(mailOptions);
// send mail with defined transport object
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
return console.error(error);
}
console.log('Message sent: ' + info.response);
});
});
};
module.exports = sendMail;