[英]how to list all the email subject in GMail?
I want to list all the email subject in my gmail account. 我想列出我的Gmail帐户中的所有电子邮件主题。
import imaplib
import email
user="xxxx"
password="yyyy"
con=imaplib.IMAP4_SSL('imap.gmail.com')
con.login(user,password)
num=int(con.select("[Gmail]/&YkBnCZCuTvY-")[1][0])
The num is 1200,there are 1200 emails in my gmail account. 这个数字是1200,我的gmail帐户中有1200封电子邮件。 I want to list all the email subject.If i want to get the first email subject ,
我想列出所有电子邮件主题。如果我想获得第一个电子邮件主题,
result,data=con.fetch(b'1', '(RFC822)')
print email.message_from_string(data[0][1])["Subject"]
The two lines can get it. 这两行就可以了。 But i can't list all the email subject as the following,how to fix it?
但是我无法列出以下所有电子邮件主题,如何解决?
for item in range(num+1):
result,data=con.fetch(str(item), '(RFC822)')
print email.message_from_string(data[0][1])["Subject"]
Try modifying your range in your for loop. 尝试在for循环中修改范围。 I believe the message ids in fetch() are '1 based'
我相信fetch()中的消息ID是“基于1”的
for item in range(1,num+1):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.