Determine incorrect email recipients



I need to determine how I can generate a list of all emails that cannot be delivered because of an incorrect email address. I want to monitor my email gateway for all emails sending from a specific address that are unable to be delivered because the email address is incorrect for whatever reason. I can easily see all SMTP errors but the key is I need to filter to only see emails that have failed which are being sent from a specific account. I then need the exact recipient address separated out so I can export it to Excel and run it against my SQL DB to correct the incorrect recipient addresses.

Thanks for any assistance or direction you can provide.


You can do this and customize what data you save with a trigger on SMTP_RESPONSE assigned to your mail gateway. Something like this, as a very very rough example:

550 -- Mailbox unavailable
551 -- Relay denied
552 -- Recipient mailbox reached max size
553 -- Mailbox name invalid
554 -- Other mail system status

var errorCodes = [550, 551, 552, 553, 554];
var theStatus = SMTP.statusCode;
var theSender= SMTP.sender;

if (errorCodes.indexOf(theStatus) > -1 && theSender) {
    Device.metricAddCount("smtp_error_count", 1);
    Device.metricAddDetailCount("smtp_error_detail_code", String(theStatus), 1);
    Device.metricAddDetailCount("smtp_error_detail_sender", theSender, 1);

This will record metrics whenever your mail gateway sends an SMTP error code related to incorrect email addresses. If you only want to commit metrics on a certain sender, maybe something like theSender == "" in the conditional statement. If you want to save the recipient too, SMTP.recipient or SMTP.recipientList is your friend. There’s plenty of data to pull off the wire; just check out the triggers documentation for the full set. If you’re just interested in printing a list of names for import elsewhere, you can export the time series to Excel or have the body of the trigger send data to a syslog receiver – you have a lot of options. (You can just write to the trigger log with a log() statement, though the trigger log is limited in size).

For this dashboard, I went into the Metric Catalog, found my custom detail metrics, and added the smtp_error_count as the base metric. I don’t have a lot of data to populate the dashboard charts, but it should give you an idea of what’s possible.


Thanks for the help. I’m making progress. The next question I have is can I create a metric which combines two or more of the strings into a single metric? See below for an example.

Current code Device.metricAddDetailCount(“smtp_error_detail_recipient”, theRecipient, 1); Device.metricAddDetailCount(“smtp_error_detail_sender”, theSender, 1);
Example: Device.metricAddDetailCount(“smtp_error_detail_string”, theSender + theRecipient, 1);

Then I could just display one variable which would include the Sender and the Recipient on one line.


Sure thing, though I’d recommend inserting some sort of delimeter between the addresses. This would add a tab character, for example. A comma would be fine too.

Device.metricAddDetailCount(“smtp_error_detail_string”, theSender + “\t” + theRecipient, 1);