mail-bounce-snoop
v2.0.3
Published
Parse email bounce notification messages
Downloads
208
Readme
This is a fork of
Node Bounce Snoop
Based on
This should help (email is messy) to detect if an email message is a bounce message
Usage
check if an email is a bounce
const EmailSnoop = require('mail-bounce-snoop');
let message = "<email as text with all header and parts>";
//using Promise
EmailSnoop.isBouncedEmail(message).then(isBounce => {
if (isBounce) {
console.log("This is a bounce message")
}
});
//using callback
EmailSnoop.isBouncedEmail(message.toString(), (isBounce) => {
if (isBounce) {
console.log("This is a bounce message")
}
});
//The message could be set with EmailSnoop.init(message), otherwise the snoop remembers the last used email
get bounce detail
const EmailSnoop = require('mail-bounce-snoop');
//using Promise
EmailSnoop.getBouncedEmailDetail(message.toString()).then(result => {
/*
* e.g. result
* {
* "recipient":"[email protected]",
* "status":"5.0.0",
* "action":"failed",
* "messageid":"<[email protected]>",
* "is":"bounce"
* }
*/
});
//using callback
EmailSnoop.getBouncedEmailDetail(message.toString(), (result) => {
//...
});
Example combination
const EmailSnoop = require('mail-bounce-snoop');
EmailSnoop.init(message);
//using the email set via init
EmailSnoop.isBounced((isBounce) => {
if (!isBounce) {
console.log("All fine");
return;
}
//using the email set via init or previous function call
EmailSnoop.getBouncedDetail().then(result => {
console.log(`Email to ${result.recipient} failed with status ${result.status}`)
});
});