Join 3,558 readers in helping fund MetaFilter (Hide)


Background Gmail automation, what program(s) to use?
March 13, 2013 6:51 AM   Subscribe

I want to write a script to automatically check for new emails with a certain gmail label, then check the message body for a link containing a certain keyword or phrase and click on it. The logic part should be easy, but what program(s) should I be using for this? Requirements...

• Needs to run in the background
• Needs to follow clicked link to continue further action on the new page
CasperJS with PhantomJS looks promising and might just do the job. But Gmail could change their UI at any minute which may break my script.

Are there any other programs that may help?
 
posted by querty to Computers & Internet (7 answers total) 2 users marked this as a favorite
 
Have you thought about using getmail to access the gmail account via IMAP?
posted by RonButNotStupid at 6:55 AM on March 13, 2013


I agree, use IMAP. I've done fairly similar things with IMAP and cron in the past, and it worked fine. Another, somewhat more advanced, approach I've used is creating a rule to forward the messages in question to a specific mailbox on a mail server I control (e.g. On AWS), and configuring the server to pipe those messages through a script that does what I want. The advantage there is that it happens instantly whenever a message arrives, not just at a fixed polling interval.

Even if you do the IMAP approach, it might be good to run it on a server, so it keeps working if you shut off your computer or something. Depends how important this is...
posted by primethyme at 7:25 AM on March 13, 2013


I don't think Gmail labels will be accessible over IMAP, as they are a proprietary Google extension rather than something that IMAP supports. Hence IMAP won't meet the OP's requirements.

Moreover Google try to prevent automated scrapers (e.g. PhantomJS) from accessing their servers; as a simple test try executing a search via Tor and you should find that you get a CAPTCHA. Hence accessing Gmail via a scraper won't work because of CAPTCHAs, and even if you get around CAPTCHAs risks having your IP address blocked by Google.

Maybe your best option is to use the Gmail APIs, but note that reading email is only possible for Gmail accounts on a Google Apps domain, hence not free.

Else your next best option are to not rely on Gmail labels and go with IMAP as per above.
posted by asymptotic at 8:06 AM on March 13, 2013


Ifttt will monitor your account for files with a specific label. Maybe you can use that trigger to do something else that follows the link.
posted by backwards guitar at 8:45 AM on March 13, 2013


Gmail labels map, not completely elegantly, to IMAP folders. IMAP is still going to be the way to go.
posted by rockindata at 8:57 AM on March 13, 2013


This sounds like something that would be very easy to do with Google Apps script (which is Javascript). There are many example out there of scripts that perform actions based on emails with a certain label.

Keeping it within the Google ecosystem will avoid all the problems that might occur with outside tools.
posted by ssg at 10:36 AM on March 13, 2013 [1 favorite]


You can easily access Gmail labels via IMAP - I've got a perl script (using the Mail::IMAPClient module) that I wrote to check my work email (hosted Google App mail) for emails with a specific label, which it then saves out to a file for another script to play with. Wouldn't be hard, I suspect, to alter it to do what you need. MeMail me, and I'll link you to a gist.
posted by hanov3r at 12:23 PM on March 13, 2013


« Older My husband and I will be in Bo...   |  I just got blood test results ... Newer »
This thread is closed to new comments.