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':
    pass
Detecting if an email is a "Delivery Status Notification" and extract information - Python