简体   繁体   English

如何列出GMail中的所有电子邮件主题?

[英]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.

相关问题 如何在通过gmail发送的电子邮件中添加主题? - How to add a subject to an email being sent with gmail? 适用于Gmail /主题的python电子邮件模块 - python email module for Gmail / subject Python:如何从 gmail API 获取电子邮件的主题 - Python: how to get the subject of an email from gmail API 如何从python中的gmail下载特定主题和日期的电子邮件附件 - how to download an email attachment from gmail in python for a particular subject and date 通过 Python 中的 Gmail API 获取给定日期之间的电子邮件列表(发件人的电子邮件、主题和正文) - Get list of emails (Sender's Email, Subject and Body) between given dates through Gmail API in Python 如何使用 python ZDB974238714CA8DE634A7CE1D0F 打印 GMail email 的主题和正文? - How can I print the subject and body of a GMail email using the python API? 程序到 Gmail 主题/从不工作的 Output 列表 - Program to Output list of Gmail Subject/From not working Python和GMail-将来自具有指定主题的指定帐户的电子邮件标记为已读 - Python and GMail - Mark email from specified account with defined subject as read 如何使用 python 自定义 gmail 主题 - How to customize gmail subject by using python 显示电子邮件主题中MultipleChoiceField输出的“可读”列表 - Display 'readable' list for output of MultipleChoiceField in email subject
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM