Skip to content

Commit

Permalink
fix(logs): send bounce information to remote log
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Feb 9, 2024
1 parent ac0b692 commit 3fd3986
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
5 changes: 4 additions & 1 deletion config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ module.exports = {
defaultZone: 'default',

// remove messages from queue if not delivered or bounced before maxQueueTime
maxQueueTime: 30 * 24 * 3600 * 1000
maxQueueTime: 30 * 24 * 3600 * 1000,

// log every poll query from queue
logQueuePolling: false
},

// plugin files to load into ZoneMTA, relative to ./plugins folder
Expand Down
17 changes: 12 additions & 5 deletions lib/mail-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,18 @@ class MailQueue {
returnOriginal: false
},
(err, item) => {
plugins.handler.remotelog((item && item.value && item.value.id) || null, (item && item.value && item.value.seq) || false, 'QUEUE_POLL', {
query,
match: item && item.value ? true : false,
error: err && err.message
});
if (this.options.logQueuePolling) {
plugins.handler.remotelog(
(item && item.value && item.value.id) || null,
(item && item.value && item.value.seq) || false,
'QUEUE_POLL',
{
query,
match: item && item.value ? true : false,
error: err && err.message
}
);
}

if (err) {
return callback(err);
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions plugins/core/email-bounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,19 @@ Status: ${isDelayed ? '4.0.0' : '5.0.0'}
maildrop.add(envelope, mail.createReadStream(), err => {
if (err && err.name !== 'SMTPResponse') {
app.logger.error('Bounce', err.message);
app.remotelog(bounce.id, bounce.seq, 'QUEUE_BOUNCE', {
queued: 'no',
bounceType: 'failure',
error: err.message
});
} else {
app.remotelog(bounce.id, bounce.seq, 'QUEUE_BOUNCE', {
queued: 'yes',
bounceType: 'failure',
bounceId: envelope.id
});
}

next();
});
});
Expand Down Expand Up @@ -206,7 +218,19 @@ Status: ${isDelayed ? '4.0.0' : '5.0.0'}
maildrop.add(envelope, mail.createReadStream(), err => {
if (err && err.name !== 'SMTPResponse') {
app.logger.error('Bounce', err.message);
app.remotelog(bounce.id, bounce.seq, 'QUEUE_BOUNCE', {
queued: 'no',
bounceType: 'delayed',
error: err.message
});
} else {
app.remotelog(bounce.id, bounce.seq, 'QUEUE_BOUNCE', {
queued: 'yes',
bounceType: 'delayed',
bounceId: envelope.id
});
}

resolve();
});
});
Expand Down

0 comments on commit 3fd3986

Please sign in to comment.