detecting error codes in emails using IMAP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

detecting error codes in emails using IMAP

Post by s.dot »

I'm writing an email bounce detection script using the PHP IMAP functions. I've gotten as far as reading the messages. Now I'm at the part where I need to scan the contents for error codes.

It would be nice if the structure of the email had the error code in it somewhere so I can just analyze that part (is there a part with the error code).

Right now I'm sticking to regexp's but they come in many different forms, such as:

Code: Select all

550: error message
Sorry, I couldn't find any host named example.tld. (#5.1.2)
Who knows how many other forms there are. I don't want to accidentally mark a valid email as bounced (though this is a dedicated noreply@example.tld mailbox).

Is this the best way to scan for an error code?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: detecting error codes in emails using IMAP

Post by josh »

theres open source mime parsers that will give you the bounce code, and whether the error was transient or permanent. Can't recall any in particular but I've found and used them before
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: detecting error codes in emails using IMAP

Post by s.dot »

The error codes are returned in the mime headers?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: detecting error codes in emails using IMAP

Post by josh »

http://www.phpclasses.org/browse/package/2691.html

I forget, but that class should do it, all you really want to look at is if its permanent or transient
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: detecting error codes in emails using IMAP

Post by s.dot »

Thanks. :)

That class isn't doing anything that I'm not doing.. which is checking for error codes and certain messages, so I think I'll stick to my code.. simply because I'll be able to more easily append to it.

It would be nice if the codes were returned in a specific body structure part or in the headers.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: detecting error codes in emails using IMAP

Post by josh »

Either way I'd add a layer behind your bounce functions to do some mime decoding.. email can come in different encodings, if you just regex the raw string you might match some text out of the email attachments. An email can have another email as an attachment. To write a 100% reliable regex you'd have to read the RFCs which would be a huge pain, 99.9% of the time a simple regex will do the job, its just that .01% that worries me lol
Post Reply