python - Python Gmail IMAP 在某个日期之后
问题描述
我正在尝试使用 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']
解决方案
任何寻找答案的人都有一个帮助我的网页:https ://automatetheboringstuff.com/chapter16/ 。
从特定日期检查的代码:
typ, data = conn.search(None, "SINCE 12-Dec-2018")
月份必须是月份的大写缩写。例如,Dec 表示 12 月。
推荐阅读
- c# - XAML:在类型中找不到属性
- javascript - 通过导航将 HTML 页面加载到 DIV 中 - 我可以直接链接到它吗?
- android - 手机显示对 x,y 坐标的影响
- c# - NavigationView - 使用 C# 添加菜单项会导致 NavigationViewItem 嵌套在生成的 NavigationViewItem 中
- python - 是否有计算产品的有效函数?
- ios - 如何在以编程方式创建实体时设置 NSManagedObjectModel 的配置。
- xcode - Xcode 10 中没有 Objects Library 按钮,只有 Snippets Library
- haskell - 如何在 Yesod 中为 selectField 构建预选选项?
- javascript - 检查至少两个数组值是否相等
- javascript - 理解 javascript 分页数学问题