Home > Python > gmail from the command prompt

gmail from the command prompt

April 30th, 2006 Leave a comment Go to comments

So over the past few weeks I've been playing around with gmail and python... and libgmail.

I've decided that more people should be introduced to this and the functionality of it, so I've created a small program to allow people to play around with it... It should run on any version of python, however, I've written it with Python 2.4 in mind and of course you'll require libgmail from the above link.

My script, checkgmail.py, provides the following functionality:

---Cut from help---
Usage: ./checkgmail.py

Options:
-a All messages
-r Only read messages
-u Only unread messages
-h Display this help message
Parameters:
-L

Only messages from a specific address
-R Read the messages (display message content)
-S Return the subject lines
-C Display a message count
-Q Run the specified query (search)
-N Number of messages to return (default: ALL)
-U GMail username
-P GMail Password (default: prompt)
---End Help---
The idea is that you can pass 1 option and multiple parameters. By default it should, and I say should because I haven't extensively tested this software, prompt for a username and a password, log in and parse all unread mail in your inbox... however it won't display any information.
Some examples you could use:
 
To check and see if your mom has sent you any mail and to check the subjects you could use this command:
checkgmail.py -u -F mom@hotmail.com -S

To read the last message your girlfriend sent you, you could run something like this
checkgmail.py -u -F gf@hotmail.com -R -N 1

One important thing to remember is that whenever you parse unread messages, even if you don't display them... libgmail is still marking them read... don't let this confuse you when you revisit gmail through your browser.

Download checkgmail.py

Peace,
HT

Categories: Python Tags:

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

  1. January 15th, 2007 at 09:12 | #1

    Hello!

    this script is great however, the -N options doesn’t work for me. the loop never breaks…

  2. January 15th, 2007 at 11:42 | #2

    i fixed it with a int cast in the options parsing

  3. January 28th, 2007 at 05:21 | #3

    Sorry I never responded Teddyber… I always forget to pay attention to my own comments… I promise to resolve that in the future..

    I’m sure the script has some issues… I threw it together rather quickly… just thought it was something cool :)

    I’m glad you enjoy it.

  4. Rajib Roychowdhury
    April 26th, 2007 at 14:13 | #4

    hay can u plz provide me the high level diagram or idea how u did it

    it will help me a lot6

  5. Amit
    January 29th, 2009 at 23:20 | #5

    Hi All i am zero in python.. could you please help me.. how it work…
    i am using linux RHEL5.0

  1. No trackbacks yet.