【问题标题】:Python Gmail IMAP After a certain datePython Gmail IMAP 在某个日期之后
【发布时间】:2019-05-19 01:17:51
【问题描述】:

我正在尝试使用 python IMAP 访问我的 gmail,但我只想阅读某个日期之后的邮件。我已将其缩小到搜索部分,但我在搜索中使用 On 和 before 并且它成功只有 after 不起作用。有没有办法在某个日期之后检索电子邮件,或者我需要全部阅读并比较日期?

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']

【问题讨论】:

    标签: python python-3.x gmail-imap


    【解决方案1】:

    任何人都在寻找答案,有一个网页对我有帮助:https://automatetheboringstuff.com/chapter16/

    从某个日期开始检查的代码:

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

    月份必须是月份的大写缩写。例如,Dec 表示 12 月。

    【讨论】:

      猜你喜欢
      • 2015-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-13
      • 2022-08-18
      • 2019-12-26
      • 2010-10-26
      相关资源
      最近更新 更多