6
import imaplib
def read():
userName = "[email protected]"
password = "xxxx"
name = '[email protected]'
email_ids = [userName]
data = []
imap_server = imaplib.IMAP4_SSL("imap.gmail.com",993)
imap_server.login(userName, password)
imap_server.select('INBOX')
da = []
status, response = imap_server.status('INBOX', "(UNSEEN)")
unreadcount = int(response[0].split()[2].strip(').,]'))
print unreadcount
status, response = imap_server.search(None, '(FROM "[email protected]")')
email_ids = [e_id for e_id in response[0].split()]
for e_id in email_ids:
_, response = imap_server.fetch(e_id, '(UID BODY[TEXT])')
da.append(response[0][1])
print da
read()
Cách sắp xếp mã ở trên, để chỉ đọc các thư chưa đọc? Ngoài ra, khi chúng tôi đọc chúng, cách đánh dấu thư là thư đã đọc bằng Python?Cách nhận tin nhắn chưa đọc và đặt cờ đọc tin nhắn qua IMAP bằng Python?