Last active
June 4, 2018 13:02
-
-
Save wwex/4dfef459d20eaf1f3125fa1b66a5602c to your computer and use it in GitHub Desktop.
[PyMemos - Mails] #python #memo #mails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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