Last active
June 2, 2019 04:02
-
-
Save guerbai/02ae36c58ceb56cbb44ea9da237e4463 to your computer and use it in GitHub Desktop.
连接gmail
This file contains 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 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