Skip to content

Commit

Permalink
fix: fixed non-TLS email bounceInfo check
Browse files Browse the repository at this point in the history
  • Loading branch information
niftylettuce committed Aug 9, 2020
1 parent 90dc2d2 commit 10733cf
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,34 @@ class ForwardEmail {
port: mx.port,
name
});
info = await transporter.sendMail({ envelope, raw });
if (this.client)
await this.client.set(key, count, 'PX', this.config.ttlMs);
try {
info = await transporter.sendMail({ envelope, raw });
if (this.client)
await this.client.set(key, count, 'PX', this.config.ttlMs);
} catch (err) {
//
// if there was `err.response` and it had a bounce reason
// and if the bounce action was defer, slowdown, or it has a category
// of blacklist, then we should retry sending it later and send a 421 code
// and alert our team in Slack so they can investigate if IP mitigation needed
//
if (isSANB(err.response)) {
const bounceInfo = zoneMTABounces.check(err.response);
// eslint-disable-next-line max-depth
if (
['defer', 'slowdown'].includes(bounceInfo.action) ||
bounceInfo.category === 'blacklist'
) {
this.config.logger.fatal(err, {
bounce_info: bounceInfo,
envelope
});
err.responseCode = 421;
}
}

throw err;
}
} else {
//
// if there was `err.response` and it had a bounce reason
Expand Down

0 comments on commit 10733cf

Please sign in to comment.