Advertisement
skip420

GMail

Aug 30th, 2022
2,037
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. import poplib
  2. import string, random
  3. import StringIO, rfc822
  4. import logging
  5.  
  6. SERVER = "pop.gmail.com"
  7. USER  = "XXXXXXXXXXX"
  8. PASSWORD = "XXXXXXXXXXX"
  9.  
  10. # connect to server
  11. logging.debug('connecting to ' + SERVER)
  12. server = poplib.POP3_SSL(SERVER)
  13. #server = poplib.POP3(SERVER)
  14.  
  15. # login
  16. logging.debug('logging in')
  17. server.user(USER)
  18. server.pass_(PASSWORD)
  19.  
  20. # list items on server
  21. logging.debug('listing emails')
  22. resp, items, octets = server.list()
  23.  
  24. # download the first message in the list
  25. id, size = string.split(items[0])
  26. resp, text, octets = server.retr(id)
  27.  
  28. # convert list to Message object
  29. text = string.join(text, "\n")
  30. file = StringIO.StringIO(text)
  31. message = rfc822.Message(file)
  32.  
  33. # output message
  34. print(message['From']),
  35. print(message['Subject']),
  36. print(message['Date']),
  37. #print(message.fp.read())  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement