We've built a web service that needs to check constantly for email messages. Basically, an user sends us an email, and the server should make actions based on that email. We could use a crontab PHP script that checks for new messages every minute, with POP. But that's kind of offensive to the popserver and not very efficient (1min is too long).
But, I've read about PUSH email using IMAP around mobile devices. In my case is not a mobile device but a webserver.
Can I push an email to my webserver and have it execute a PHP script? We're using GMail as POP/SMTP/IMAP server.
EDIT 1 from the answers, we figured out:
there must be a 24/7 running process (daemon) on my webserver checking for emails
this daemon may communicate with Gmail using: i) POP with NOOP coomand or ii) IMAP with IDLE command
What's the best? POP or IMAP? Google seems to invite more the use of IMAP.
I don't want to overuse gmail (what's their 'fair use' for checking email? every 10secs?
Also check relevant answers here for more info
There's an old (but great) article on Evolt about piping emails to a php script, which therefore gets the full content of the email and can act on it.
http://www.evolt.org/article/Incoming_Mail_and_PHP/18/27914/index.html
If you want to use postfix as your MTA you can alias an email address to any executable like this. It really isn't that difficult to setup on a *nix box...
I've no experience with IMAP, but had to do the same thing. If I were you, I'd install Postfix and use the pipe command (basically lets you run an arbitrary script) to invoke a small http client that parses the email and sends it to your server.
You can replace postfix with whatever MTA you'd like, of course. The point is: don't implement your own email server. Use an existing one and use its hooks to send the mail off to where ever it is you want, however it is you want.