-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsendMail.js
52 lines (40 loc) · 1.7 KB
/
sendMail.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
const config = require('./config.json')
var nodemailer = require('nodemailer');
var email = config.email;
var password = config.password;
var recipient = config.recipient;
var emailSuject = config.emailSuject;
var emailText = config.emailText;
var emailHtml = config.emailHtml;
// create reusable transporter object using SMTP transport
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: email,
pass: password
}
});
//You need to allow less secure app if you want to use Gmail mail service.
//Follow this doc (https://support.google.com/accounts/answer/6010255?hl=en)
// and Change account access for less secure apps
var mailOptions = {
from: email, // sender address
to: recipient, // list of receivers
subject: emailSuject, // Subject line
text: emailText, // plaintext body
html: emailHtml // html body
};
// send mail with defined transport object
var send = () => {
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log(error);
}else{
console.log('Message sent: ' + info.response);
}
});
}
module.exports.sendTestEmail = function () {
send();
};
module.exports.send = send;