Some mail servers implement RFC 3464. Those that do will typically generate Delivery Status Notifications with a message header Content-Type of multipart/report and three component parts (text/plain, message/delivery-status and message/rfc822). So you could detect those characteristics of the message and process accordingly. The message will generally look like this:
From: "Mail Delivery System" <[email protected]>
Subject: Delivery Status Notification (Failure) Content-Type:
multipart/report; report-type=delivery-status
Content-Type: text/plain A human readable explanation of the
Delivery Status Notification.
Content-Type: message/delivery-status A structured machine readable
reason for the Delivery Status Notification.
Content-Type: message/rfc822 The original message.
For those mail servers that generate Delivery Status Notifications in an unstructured format, it is probably still necessary to detect their notifications by analysing the text of the From: and Subject: message headers.