tags:

views:

36

answers:

1

Is there any way to trigger a php script when a new email arrives on Google Apps (Gmail)? I've figured out a way to poll the inbox to look for new messages, but I'd ideally like a more event-based solution. Basically I need it to be run from a server somewhere which would parse new email messages and process itself according to the contents of the message.

A: 

Most mail transfer agents let you put in filters that can process incoming mail through a program as it arrives. SpamAssassin works this way, for example.

Because Gmail is hosted, you can't exactly do that.

The only realistic answer in this case is polling. Thankfully Gmail exposes both POP3 and IMAP access, so checking should be very simple. There are a few comprehensive mail reading libraries out there, or you could be insane and poke at IMAP directly.

Edit: Because you're on Google Apps, there's also an Atom feed of unread messages, though you'd still need something to poll the feed, unless you happen to have something handy that will do the polling for you and fire up requests. I vaguely recall something like this existing, but I don't recall what it's called...

Charles
Perhaps he could have Gmail forward new messages (while also retaining the message as unread in the Gmail inbox) to another server where he has control over the MTA filters. That may eliminate the need for polling.
webbiedave
Oh, that's a good one also.
Charles
Good answer (confirms what I was thinking) and good suggestion (forwarding). Can't believe I didn't think of the forwarding bit.
dosboy