5

I'm fetching emails from a POP3 server and I'd like to make a difference between a regular email and DSN (Delivery Status Notification) / NDR (Non-Delivery Report/Receipt) messages.

What is the best/safest way to identify those messages? Are there any particular message-headers I should be looking for?

Thanks in advance!

Mats
  • 14,902
  • 33
  • 78
  • 110

1 Answers1

7

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" <MAILER-DAEMON@example.com>
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.

Community
  • 1
  • 1
Mike Green
  • 2,031
  • 2
  • 18
  • 16