Guest User

Untitled

a guest
Jun 18th, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. def get(self):
  2. mail = imaplib.IMAP4('xxx@gmail.com',993)
  3.  
  4. mail.login('email@gmail.com','password')
  5.  
  6. type, data = mail.search(None, 'ALL')
  7. mail_ids = data[0]
  8.  
  9. id_list = mail_ids.split()
  10. first_email_id = int(id_list[0])
  11. latest_email_id = int(id_list[-1])
  12.  
  13. for i in range(latest_email_id,first_email_id, -1):
  14. typ, data = mail.fetch(i, '(RFC822)' )
  15.  
  16. for response_part in data:
  17. if isinstance(response_part, tuple):
  18. msg = email.message_from_string(response_part[1])
  19. email_subject = msg['subject']
  20. email_from = msg['from']
  21. self.response.headers["Content-Type"] = "text/plain"
  22. self.response.write("From:" + email_from)
  23. self.response.write("Subject:" + email_subject)
  24.  
  25.  
  26. routes = [('/', ReadMail),]
  27.  
  28. app = webapp2.WSGIApplication(routes, debug=True)
Add Comment
Please, Sign In to add comment