【问题标题】:Trying to return emails within past 24 hours using ExchangeLib尝试使用 ExchangeLib 在过去 24 小时内返回电子邮件
【发布时间】:2019-08-16 03:41:21
【问题描述】:

我正在尝试使用 ExchangeLib 返回过去 24 小时内收件箱中的所有电子邮件。我目前已将其设置为返回收件箱中的最新电子邮件,我只需要 24 小时部分的帮助。这是我目前所拥有的:

credentials = Credentials('My@email', 'password')
account = Account('My@email', credentials=credentials, autodiscover=True)

for item in account.inbox.all().order_by('-datetime_received')[:1]:
    print(item.subject, item.sender.email_address)

    html = item.unique_body

    soup = BeautifulSoup(html, "html.parser")
    for span in soup.find_all('font'):
        return(item.subject, item.sender.email_address, span.text)

我一直在尝试查找有关如何解决此问题的参考资料,但老实说,我找不到太多。有什么建议吗?

【问题讨论】:

    标签: python email exchange-server exchangelib


    【解决方案1】:

    您需要在datetime_received 字段上添加大于过滤器:

    from datetime import timedelta
    from exchangelib import UTC_NOW
    
    since = UTC_NOW() - timedelta(hours=24)
    for item in account.inbox.all()\
            .filter(datetime_received__gt=since)\
            .order_by('-datetime_received'):
        # Do something
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-14
      • 1970-01-01
      • 2019-08-28
      • 1970-01-01
      • 2015-05-29
      相关资源
      最近更新 更多