daily pastebin goal
56%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import imaplib
  2. import email
  3. import re
  4.  
  5. print('imported')
  6.  
  7. mail = imaplib.IMAP4_SSL('imap.gmail.com',993)
  8.  
  9. user = 'xxxxxx@gmail.com'
  10. pwd = 'xxxxxx'
  11.  
  12. mail.login(user,pwd)
  13. print('successfully logged in')
  14. mail.list()
  15. print(mail.list())
  16. print('selecting inbox')
  17.  
  18. mail.select('INBOX')
  19. print('inbox selected')
  20.  
  21. # selecting all items / emails
  22. result, data = mail.uid('search', None, "ALL")
  23.  
  24. # transforming tuple into list / splitting them
  25.  
  26. inbox_item_list = data[0].split()
  27.  
  28. for item in inbox_item_list:
  29.     result2, email_data = mail.uid('fetch', item, '(RFC822)')
  30.     raw_email = email_data[0][1].decode("utf-8")
  31.     email_message = email.message_from_string(raw_email)
  32.  
  33.     mail_body = email_message.get_payload()
  34.     emails = re.findall(b'[\w\.-]+@[\w\.-]+', mail_body)
  35.     for email in emails:
  36.         print(email)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top