[英]IMAP, view email's labels, Python & Gmail
How can I see what labels an email has?如何查看 email 有哪些标签?
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('myaccountxyz@gmail.com', mypassword)
mail.select("my-folder") # finds emails with this label
result, data = mail.uid('search', None, 'all')
for email_uid in data[0].split():
result, data_single = mail.uid('fetch', email_uid, '(RFC822)')
raw_email = data_single[0][1]
email_message = email.message_from_string(raw_email)
sender = email_message['From']
# get list of this email's labels
I haven't tried this code myself, but according to Google IMAP Extensions , you should be able to just fetch the X-GM-LABELS
item:我自己没有尝试过这段代码,但根据Google IMAP Extensions ,您应该能够获取X-GM-LABELS
项目:
typ, dat = mail.uid('fetch', email_uid, 'X-GM-LABELS')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.