Following code snippet prints new (unread) mail in your inbox:
# -*- coding: utf-8 -*-
import feedparser
import urllib2
# Create http basic auth handler
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password('New mail feed', 'https://mail.google.com/',
'USERNAME@DOMAIN', 'PASSWORD')
# Open url using the auth handler
opener = urllib2.build_opener(auth_handler)
feed_file = opener.open('https://mail.google.com/mail/feed/atom/')
# Parse feed using feedparser
d = feedparser.parse(feed_file)
# Print mail count and mails
print 'Mail count:', d.feed.fullcount
for entry in d.entries:
print '----------------------------------------------'
print 'Author: ', entry.author
print 'Subject:', entry.title
print 'Summary:', entry.summary
Just change USERNAME and PASSWORD. You also need to download feedparser which is free to use, or write one yourself.Have fun!
thank u for this tutorial, but how secure is it? =)
ReplyDeleteIt should be secure (if you mean sending your password over the network) since the traffic is encrypted using ssl (https) to the web-server.
ReplyDeleteI've inspected the network traffic with wireshark and it appears to be ok (encrypted).