特定日期后Python Gmail IMAP



我正在尝试使用python imap访问我的gmail,但我想在特定日期后仅阅读消息。我已经将其范围缩小到搜索部分,但是我在搜索中和以前都使用,并且仅此后才能成功。是否有一种方法可以在特定日期后检索电子邮件,或者我需要阅读全部内容并比较日期?

typ, data = conn.search(None, "After 12/12/18")
try:
    for num in data[0].split():
        typ, msg_data = conn.fetch(num, '(RFC822)')
        for response_part in msg_data:
            if isinstance(response_part, tuple):
                msg = email.message_from_bytes(response_part[1])
                subject=msg['subject']
                by = msg['from']
                to = msg['to']

错误:

imaplib.IMAP4.error: SEARCH command error: BAD [b'Could not parse command']

任何在此寻求答案的人都有一个帮助我的网页:https://automatetheboringstuff.com/chapter16/。

从特定日期检查的代码:

typ, data = conn.search(None, "SINCE 12-Dec-2018")

这个月必须是本月的大写缩写。例如,十二月的十二月。

最新更新