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!
A Delivery Status Notification (DSN), or simply a bounce, is an automated electronic mail message from a mail system informing the sender of another message about a delivery problem. The original message is said to have bounced. Errors can occur at multiple places in mail delivery.
When you get mail from a "MAILER-DAEMON" or a "Mail Delivery Subsystem" with a subject like "Failed Delivery" or similar, it means that an email you sent was undeliverable and has been "bounced" back to you. These messages are produced automatically and usually include a reason for the delivery failure.
A DNS query (also known as a DNS request) is a demand for information sent from a user's computer (DNS client) to a DNS server. In most cases a DNS request is sent, to ask for the IP address associated with a domain name.
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-statusContent-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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With