Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ################
- # Send emails
- ################
- import smtplib
- conn = smtplib.SMTP('smtp.gmail.com', 587)
- conn.ehlo() #start the connection
- conn.starttls() #start encryption before passing password
- conn.quit()
- ################
- # Read emails
- ################
- import imapclient
- conn = imapclient.IMAPClient('imap.gmail.com', ssl=True)
- conn.select_folder('INBOX', readonly=True)
- UIDs = conn.search(['SINCE 20-Aug-2015']) #returns a list of unique ids of the emails we are filtering
- rawMessage = conn.fetch([46465], ['BODY[]'
- #to parse the raw message and get the single fields ot of the email
- import pyzmail
- message = pyzmail.PyzMessage.factory(rawMessage[46465][b'BODY[]'])
- message.get_ subject()
- message.get_addresses('from')
- message.get_addresses('to')
- message.get_addresses('bbc')
- message.text_part #`the email can be text or html
- mesasge.html_part
- message.text_part.get_payload().decode('UTF-8')
- conn.list_folders() #list all the directories of the email box
- conn.select_folder('INBOX', readonly=False)
- UIDs = conn.search(['ON 24-Aug-2015'])
- conn.delete_messages(UIDs)
Advertisement
Add Comment
Please, Sign In to add comment