gpt4 book ai didi

python - 使用 imaplib 在 Gmail 中搜索

转载 作者:太空狗 更新时间:2023-10-30 02:35:01 25 4
gpt4 key购买 nike

import imaplib

user = raw_input("Enter your GMail username:")
pwd = getpass.getpass("Enter your password: ")


m = imaplib.IMAP4_SSL("imap.gmail.com")
m.login(user,pwd)
m.select("[Gmail]/Inbox") # here you a can choose a mail box like INBOX instead
m.search("NEW")

我试图通过 Python 中的 imap 在 Gmail 中仅选择新邮件。问题是,我总是收到以下错误:

imaplib.error: command SEARCH illegal in state AUTH

我在谷歌上搜索了一下,读到我必须使用 imap4,但我已经在使用它了,我真的不知道如何解决它。

最佳答案

问题好像是没有叫[Gmail]/Inbox的邮箱.可以通过调用 m.list() 获得所有有效邮箱的列表。 .

我通过使用 Python 的交互式 shell(使用 Python 2.6)发现了这一点,它显示了 IMAP 服务器对每个 IMAP 操作的响应。

注意:使用 Python 交互式 shell 时,导入 pprint并调用 pprint.pprint(m.<method of m>(<params>))对于一些发送回大量信息的 IMAP 命令来说,这可能是个好主意。

关于python - 使用 imaplib 在 Gmail 中搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5161053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com