GmailRCS is a way to use your Gmail account as a lightweight Revision Control System (RCS) in order to backup and restore the different versions of your source code. The software is written in Python, using libgmail
GmailRCS: http://sourceforge.net/projects/gmailrcs/
Tags: Gmail, Programming, Gr33n Data
Are you looking for my non-technical blog?
This is now my technical-only blog, my non-technical blog is here.
Showing posts with label Google. Show all posts
Showing posts with label Google. Show all posts
23 December 2005
16 December 2005
Python - libgmail Tutorial
This is a short tutorla about libgmail. Which is a Library to provide access to Gmail via Python.
Tabs are important in python as they indicate the different code blocks, since they do not have "{" and "}" like those in C and C++. So I'll replace the tabs here with [TAB], since it's hard to write the proper format in HTML.
First of all lets see how can we get the libgmail help, a.k.a man pages:
Tags: Python, Gmail, Gr33n Data
First of all lets see how can we get the libgmail help, a.k.a man pages:
>>>import libgmailThen lets see how can we retrieve the messages in our the inbox:
>>>help(libgmail)
>>>import libgmailNow lets say we want to print all the attached files in all the messages labled by "projectx"
>>>ga = libgmail.GmailAccount("username@gmail.com", "password")
>>>ga.login()
>>>folder = ga.getMessagesByFolder("inbox", True)
>>>for thread in folder:
>>>[TAB]print "Thread:", thread.id, "Subject:", thread.subject
>>>[TAB]for msg in thread:
>>>[TAB][TAB]print "Msg:", msg.id, ",Author", msg.author, ",Subject:", msg.subject
>>>import libgmailYou may also send a message this way:
>>>ga = libgmail.GmailAccount("username@gmail.com", "password")
>>>ga.login()
>>>folder = ga.getMessagesByLabel("projectx", True)
>>>for tread in folder:
>>>[TAB]for msg in thread:
>>>[TAB][TAB]for attach in msg.attachments:
>>>[TAB][TAB][TAB]print attach._getContent()
>>>import libgmailTo send attachmented files into the message:
>>>ga = libgmail.GmailAccount("username@gmail.com", "password")
>>>ga.login()
>>>msg=libgmail.GmailComposedMessage("friend@gmail.com", "SubjectHere", "BodyHere")
>>>ga.sendMessage(msg)
>>>import libgmailFinally I've noticed that sometimes the sendMessage() function fails - returns "HTTP Error 404: Not Found", and hope that they are going fix it soon. Actually the function fails on the first time but when you call it again it works, so you may use a "try-except" statement like the one below:
>>>ga = libgmail.GmailAccount("username@gmail.com", "password")
>>>ga.login()
>>>myFiles = ["/file1", "/file2", "/file3"]
>>>msg=libgmail.GmailComposedMessage("friend@gmail.com", "SubjectHere", "BodyHere", filenames=myFiles)
>>>ga.sendMessage(msg)
>>>try:
>>>[TAB]ga.sendMessage(msg)
>>>except:
>>>[TAB]ga.sendMessage(msg)
Tags: Python, Gmail, Gr33n Data
Subscribe to:
Posts (Atom)