Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get(self):
- mail = imaplib.IMAP4('xxx@gmail.com',993)
- mail.login('email@gmail.com','password')
- type, data = mail.search(None, 'ALL')
- mail_ids = data[0]
- id_list = mail_ids.split()
- first_email_id = int(id_list[0])
- latest_email_id = int(id_list[-1])
- for i in range(latest_email_id,first_email_id, -1):
- typ, data = mail.fetch(i, '(RFC822)' )
- for response_part in data:
- if isinstance(response_part, tuple):
- msg = email.message_from_string(response_part[1])
- email_subject = msg['subject']
- email_from = msg['from']
- self.response.headers["Content-Type"] = "text/plain"
- self.response.write("From:" + email_from)
- self.response.write("Subject:" + email_subject)
- routes = [('/', ReadMail),]
- app = webapp2.WSGIApplication(routes, debug=True)
Add Comment
Please, Sign In to add comment