/
email.js
36 lines (30 loc) · 964 Bytes
/
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
// packages from npm
var nodemailer = require("nodemailer");
var config = require(process.env.CONFIG_PATH + '/config.js');
// create reusable transport method (opens pool of SMTP connections)
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: config.emailUser,
pass: config.emailPass
}
});
var sendEmail = function(text) {
var mailOptions = {
from: "chat",
to: config.emailUser,
subject: text,
text: text, // plaintext body
}
// send mail with defined transport object
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
// if you don't want to use this transport object anymore, uncomment following line
//smtpTransport.close(); // shut down the connection pool, no more messages
});
};
module.exports = sendEmail;