-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (36 loc) · 997 Bytes
/
index.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
var nodemailer = require('nodemailer');
var fs = require('fs');
var smptCfg = require('./package').config.smtp;
var mailBodyPath = './index.html',
mailOptions = {
from: '"no-reply 測試信" <[email protected]>',
to: null,
bcc: '[email protected];[email protected]',
subject: '[測試信件]'
// text: 'That was easy!',
// html: mailBody // after readfile
};
var transporter = nodemailer.createTransport({
host: smptCfg.host,
port: smptCfg.port,
secure: smptCfg.secure, // true for 465, false for other ports
auth: {
user: smptCfg.auth.user,
pass: smptCfg.auth.pass
}
});
// console.log(fs);
fs.readFile(mailBodyPath, 'utf8', function (err, mailBody) {
if (err) {
return console.log(err);
}
// console.log(mailBody);
mailOptions.html = mailBody;
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
});