Skip to content

Instantly share code, notes, and snippets.

@guerbai
Last active June 2, 2019 04:02
Show Gist options
  • Save guerbai/02ae36c58ceb56cbb44ea9da237e4463 to your computer and use it in GitHub Desktop.
Save guerbai/02ae36c58ceb56cbb44ea9da237e4463 to your computer and use it in GitHub Desktop.
连接gmail
import imaplib
def open_connection(verbose=False):
connection = imaplib.IMAP4_SSL('imap.gmail.com', 993)
# username = gmail["username"]
# password = gmail["password"]
username = 'silverdismond@gmail.com'
password = 'qwer`123'
connection.login(username, password)
return connection
c = open_connection()
c.select('INBOX', readonly=True)
print 'HEADER:'
typ, msg_data = c.fetch('1', '(BODY.PEEK[HEADER])')
for response_part in msg_data:
if isinstance(response_part, tuple):
print response_part[1]
print 'BODY TEXT:'
typ, msg_data = c.fetch('1', '(BODY.PEEK[TEXT])')
for response_part in msg_data:
if isinstance(response_part, tuple):
print response_part[1]
typ, response = c.store(msg_ids, '+FLAGS', r'(\Deleted)')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment