Skip to content

Instantly share code, notes, and snippets.

@wwex
Last active June 4, 2018 13:02
Show Gist options
  • Save wwex/4dfef459d20eaf1f3125fa1b66a5602c to your computer and use it in GitHub Desktop.
Save wwex/4dfef459d20eaf1f3125fa1b66a5602c to your computer and use it in GitHub Desktop.
[PyMemos - Mails] #python #memo #mails
import imapclient
conn = imapclient.IMAPClient('imap.gmail.com', ssl=True)
conn.login('[email protected]', 'password')
conn.select_folder('INBOX', readonly=True)
UIDs = conn.search(['SINCE 20-Aug-2015'])
rawMessage = conn.fetch([47474], ['BODY[]', 'FLAGS']) # 47474 <== UIDs[0]
conn.list_folder()
conn.delete_messages([47474, 47475])
import pyzmail
message = pyzmail.PyzMessage.factory(rawMessage[47474][b'BODY[]'])
message.get_subject()
message.get_addresses('from')
message.get_addresses('to')
message.get_addresses('bcc')
message.text_part
message.html_part
message.text_part.get_payload().decode('UTF-8')
message.text_part.charset
import smtplib
conn = smtplib.SMTP('smtp.gmail.com', 587)
conn.ehlo()
conn.starttls()
# conn.login('[email protected]', 'password')
conn.login('[email protected]', 'password')
conn.sendmail('[email protected]', '[email protected]',
'Subject: The mail topic \n\nThis is the message body\nstill body, thanks for the fish\n\nWW')
conn.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment