How do you detect "bounceed" email replies and other automated responses for failed delivery attempts in Python?
I'm implementing a simple server to relay messages between email and comments inside a custom web application. Because my comment model supports a "reply to all" feature, if two emails in a comment thread become invalid, there would possibly be an infinite email chain where my system would send out an email, get a bounceback email, relay this to the other invalid email, get a bounceback email, relay this back to the first, ad infinitum.
I want to avoid this. Is there a standard error code used for bounced or rejected emails that I could check for, ideally with Python's imaplib package?
Avoid reacting to messages whose Return-Path isn't in From, or that contain an Auto-Submitted or X-Loop header field, or that have a bodypart with type multipart/report.
You may also want to specify Auto-Submitted: auto-generated on your outgoing mail. I expect that if you do as Max says that'll take care of the problem, but Auto-Submitted isn't expensive.
How to detect bounce emails