Skip navigation

Category Archives: Google Apps

import email, getpass, imaplib, os

detach_dir = '.'

### directory where to save attachments (default: current)

m = imaplib.IMAP4_SSL('', 993)
keywordsSearch = 'bananas oranges'
searchString = "(ALL SUBJECT '%s')" % keywordsSearch

###, "(ALL SUBJECT 'bananas oranges')")
resp, items =, searchString)
items = items[0].split()
for emailid in items:
    resp, data = m.fetch(emailid, "(RFC822)")
    email_body = data[0][1]
    mail = email.message_from_string(email_body)
    if mail.get_content_maintype() != 'multipart':
    print "["+mail["From"]+"] :" + mail["Subject"]
    for part in mail.walk():
        if part.get_content_maintype() == 'multipart':
        if part.get('Content-Disposition') is None:
        filename = part.get_filename()
        counter = 1
        if not filename:
            filename = 'part-%03d%s' % (counter, 'bin')
            counter += 1
        att_path = os.path.join(detach_dir, filename)
        if not os.path.isfile(att_path) :
            fp = open(att_path, 'wb')

You can’t use ‘tidy’ python binding with App Engine as far as I know so use this for cleaning up your xml and html characters:

import cgi
string = str('I hate monkey & hyena characters')

Should print out:

I hate monkey & hyena characters

Here’s a quick set up for Google App Engine’s SDK on Nginx.

Read More »

You can send more than 500 emails per day by using Google’s recommendation of creating more than one account for sending.

Read More »