Ways to identify bounced or undeliverable mail programmatically

Brand new Axigen admin here, so go please go easy on me!

I’m looking for a way to identify bounced or otherwise undeliverable emails sent from a few specific email accounts. I need to be able to deliver transactional notifications and report notifications (notifying the user that new data is available). In either case, the recipient has provided their email address to me. Sometimes they mis-type it. Sometimes they stop using the email address. Sometimes the account is just over-quota (a good indicator that they aren’t using the address anymore I suppose). I would like to be able to collect the from email address, the to email address, and the error code (e.g. 550 for non-existent email address) along with any message text from the recipients SMTP server.

The ultimate goal here is to identify bad email addresses so that I can remove them from the system, and/or flag that user/email so that I can ask them to update their email address.

I see three different types of strategies to accomplish this, but I’m unsure of which one might be best. Also unsure if I’m missing some easier way of doing this.

  1. Parse inbox via IMAP and look delivery failure notices
  2. Parse log files and try to identify delivery failures
  3. Set up logging in Axigen in a way such that it can report delivery failures in a format I can consume (?)

Here is what I’ve seen so far:

I see that Axigen will put an email in the inbox of the sender, using the subject line “Failure notice”. I can access the Inbox programmatically via IMAP and parse the message. But the message is not in a terribly nice format for parsing. I also did not see a way to alter the way these messages are formatted. I think these emails are only sent if there is an immediate permanent failure.

I also see that you can configure (from WebAdmin: Queue → Processing → Delivery Reports → Permanent Delivery Errors) so called “Permanent Delivery Errors” which sends an email with the subject line “Permanent failure notice”. Here you have a template that you can specify what format the email should be in (cool!). But it looks like you are only going to get one of these if there were first temporary failures (like DNS lookup failed etc).

I also checked the log files (this is the way I did it with my previous email server), but found them to be difficult to read, at least programmatically. I see several different phrases used to describe delivery failures, like:

Here is one:

2023-04-03 22:46:36 -0500 08 X15AYW SMTP-OUT:000002F7: **RCPT xyz@gamil.com rejected with message**: sorry, no mailbox here by that name (#5.1.1 - chkuser)
2023-04-03 22:46:36 -0500 08 X15AYW SMTP-OUT:000002F7: No RCPT accepted for mail 13A78D; aborting transaction
2023-04-03 22:46:36 -0500 08 X15AYW SMTP-OUT:000002F7: Set recipient <xyz@gamil.com> state to RELAY ERROR

And another, this time with a slightly different format:

2023-04-04 07:30:26 -0500 08 X15AYW SMTP-OUT:0000046C: **Error sending data for mail 1098C7**; server response code: 552 (1 Requested mail action aborted, mailbox not found)
2023-04-04 07:30:26 -0500 08 X15AYW SMTP-OUT:0000046C: Set recipient <xyz@yahoo.com> state to RELAY ERROR

This one I got before I had SPF and DKIM set up properly, so I probably won’t see it much, but the fact that it CAN be reported, means it needs to be addressed:

2023-04-02 20:56:11 -0500 08 X15AYW SMTP-OUT:000012BD: **BDAT chunk rejected with message**: 5.7.1 [xx.xx.xx.xx      12] Our system has detected that this message is 5.7.1 likely unsolicited mail. To reduce the amount of spam sent to Gmail, 5.7.1 this message has been blocked. Please visit 5.7.1  https://support.google.com/mail/?p=UnsolicitedMessageError 5.7.1  for more information. u2-20020a0deb02000000b005456c355110si6549145ywe.460 - gsmtp
2023-04-02 20:56:11 -0500 08 X15AYW SMTP-OUT:000012BD: Set recipient <abc@gmail.com> state to RELAY ERROR

My biggest concern with trying to parse log files is that a simple or casual change by Axigen in future releases will break my parsing code. Not to mention I have no real way of knowing if I’m covering all the bases on identifying undeliverable mail. And worst of all, I can’t tell which email address was the sender… I see what I think is some sort of mail ID, but how do I look up that mail ID to figure out who the sender was?

Ideally, there would be a configurable log file that I could have Axigen output. But I don’t see much for customization on that front. Basically, you get what they want to give you and thats it (or am I wrong?)

I have no familiarity with SNMP, but I see that you can configure a listener. Would SNMP give me the info I’m looking for?

I also see Axigen has something called a Log Server Listener… But from what I can tell, that is for logging from one Axigen server to another (? not sure how that is useful).

Anyway, I’m not finding a really slick way to identify these undeliverable emails. If anyone has any insight, I’d love to hear it.