-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail.js
57 lines (52 loc) · 1.62 KB
/
email.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
49
50
51
52
53
54
55
56
57
"use strict";
var nodemailer = require('nodemailer');
// var options = {
// user: 'robot',
// pass: '',
// mailServerFqdn: 'smtp.gmail.com',
// fromEmail: 'HashPlex Robot <robot@hashplex.com>',
// toEmail: 'bernie.rihn@gmail.com',
// subject: 'UNFOLLOWED AGAIN',
// plaintextMessage: '',
// htmlMessage: ''
// }
// var mailOptions = {
// from: 'HashPlex Robot <robot@hashplex.com>', // sender address
// to: 'bernie.rihn@gmail.com', // list of receivers
// subject: 'UNFOLLOWED AGAIN', // Subject line
// text: 'unfollowed...', // plaintext body
// html: '' // html body
// };
function sendEmail(options) {
return new Promise((resolve, reject) => {
var mailOptions = {
from: options.fromEmail,
to: options.toEmail,
subject: options.subject,
text: options.plaintextMessage,
html: options.htmlMessage
};
console.log('OPTIONS: ' + JSON.stringify(options));
console.log('MAILOPTIONS: ' + JSON.stringify(mailOptions));
var smtpConfig = {
host: options.mailServerFqdn,
port: options.mailServerPort,
secure: true, // use SSL
auth: {
user: options.user + '@' + options.emailDomain,
pass: options.pass
}
};
console.log('SMTP CONFIG: ' + JSON.stringify(smtpConfig));
var transporter = nodemailer.createTransport(smtpConfig);
transporter.sendMail(mailOptions, (error, info) => {
if(error) {
return reject(new Error(error));
} else {
// console.log('Message sent: ' + info.response);
resolve(info);
}
});
});
}
module.exports = sendEmail;