|
@@ -40,7 +40,7 @@ app.post('/send', function(req, res, next) {
|
40
|
40
|
// text entered by the user
|
41
|
41
|
params.html = pug.renderFile('template.pug', params);
|
42
|
42
|
|
43
|
|
- log.info('Sending message from ' + content.from);
|
|
43
|
+ log.info('Sending message from ' + params.from);
|
44
|
44
|
|
45
|
45
|
// Send the email to all users
|
46
|
46
|
sendMails(params, function(err, infos) {
|
|
@@ -76,16 +76,16 @@ app.listen(port, function() {
|
76
|
76
|
function sendMails(params, update, done) {
|
77
|
77
|
let mails = settings.recipients.map((recipient) => {
|
78
|
78
|
// Promise for each recipient to send each mail asynchronously
|
79
|
|
- return new Promise((sent) => {
|
|
79
|
+ return new Promise((sent) => {
|
80
|
80
|
params.to = recipient;
|
81
|
81
|
// Send the email
|
82
|
82
|
transporter.sendMail(params, (err, infos) => {
|
83
|
|
- // Promise callback
|
84
|
|
- sent();
|
85
|
83
|
if(err) {
|
86
|
|
- return next(err, recipient);
|
|
84
|
+ return update(err, recipient);
|
87
|
85
|
}
|
88
|
|
- next(null, infos);
|
|
86
|
+ update(null, infos);
|
|
87
|
+ // Promise callback
|
|
88
|
+ sent();
|
89
|
89
|
});
|
90
|
90
|
});
|
91
|
91
|
});
|
|
@@ -98,10 +98,10 @@ function sendMails(params, update, done) {
|
98
|
98
|
// infos: infos provided by nodemailer
|
99
|
99
|
// return: nothing
|
100
|
100
|
function logStatus(infos) {
|
101
|
|
- if(infos.accepted.length) {
|
102
|
|
- log.info('Message sent to ' + status.accepted[0]);
|
|
101
|
+ if(infos.accepted.length !== 0) {
|
|
102
|
+ log.info('Message sent to ' + infos.accepted[0]);
|
103
|
103
|
}
|
104
|
|
- if(infos.rejected.length) {
|
105
|
|
- log.info('Message failed to send to ' + status.rejected[0]);
|
|
104
|
+ if(infos.rejected.length !== 0) {
|
|
105
|
+ log.info('Message failed to send to ' + infos.rejected[0]);
|
106
|
106
|
}
|
107
|
107
|
}
|