a guest Aug 10th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- import imaplib
- import email
- import re
- mail = imaplib.IMAP4_SSL('imap.gmail.com',993)
- user = 'email@example.com'
- pwd = 'xxxxxx'
- print('successfully logged in')
- print('selecting inbox')
- print('inbox selected')
- # selecting all items / emails
- result, data = mail.uid('search', None, "ALL")
- # transforming tuple into list / splitting them
- inbox_item_list = data.split()
- for item in inbox_item_list:
- result2, email_data = mail.uid('fetch', item, '(RFC822)')
- raw_email = email_data.decode("utf-8")
- email_message = email.message_from_string(raw_email)
- mail_body = email_message.get_payload()
- emails = re.findall(b'[\w\.-]+@[\w\.-]+', mail_body)
- for email in emails:
RAW Paste Data