import email
msg = email.message_from_string(emailstr)
if (msg.is_multipart() and len(msg.get_payload()) > 1 and
msg.get_payload(1).get_content_type() == 'message/delivery-status'):
# email is DSN
print(msg.get_payload(0).get_payload()) # human-readable section
for dsn in msg.get_payload(1).get_payload():
print('action: %s' % dsn['action']) # e.g., "failed", "delivered"
if len(msg.get_payload()) > 2:
print(msg.get_payload(2)) # original message
print(email_message_list[t][3].get_payload(0).get_payload()) source: https://stackoverflow.com/questions/5298285/detecting-if-an-email-is-a-delivery-status-notification-and-extract-informatio