I'm on Ubuntu and I have some email accounts on gmail that I would like to poll every once in awhile to see if there's any new mail. I want to write a script for this, so that everytime I run the script it tells me how many new messages I have from my account(s). What application would I have to run from the command line to do such a thing? Everything I find online talks about using the "mail" command, but that seems to check some local mail directory instead of my remote email (obviously, any such application would also require me to configure it to log into my account with the correct password).
Asked
Active
Viewed 4,164 times
2 Answers
3
Python makes it fairly easy to check IMAP accounts without needing to install any extra packages.
There's a good writeup at Yuji Tomita's blog on how to use python's imaplib
to talk to Gmail. http://yuji.wordpress.com/2011/06/22/python-imaplib-imap-example-with-gmail/

Sam Mussmann
- 5,883
- 2
- 29
- 43
-
Yes that guide helped a lot. In the end, the following search query seemed to do just what I wanted: mail.search(None, "UNSEEN"). And after that, getting the id list and printing its length gives the number of new messages. – bhh1988 Aug 05 '12 at 00:48
3
Try the following:
curl -u user@gmail.com:password --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if /<name>/; print "$2\n" if /<(title|name)>(.*)<\/\1>/;' | espeak

Tim Post
- 33,371
- 15
- 110
- 174

user2043985
- 31
- 1