如何使用Python在Gmail中找到两个给定日期之间的电子邮件



我正在尝试使用python为gmail制作一个电子邮件解析器。 我想过滤两个给定日期(开始日期和结束日期(之间的电子邮件。如何过滤电子邮件?

我已经尝试了一些东西,可以给我收件箱的所有邮件,但我只想要指定日期之间的邮件

下面是代码的一部分:

import imapclient
import pprint
imapObj = imapclient.IMAPClient('imap.gmail.com', ssl=True)
email_id = input("Please enter your email_id: ")
import getpass
pswd = getpass.getpass('Password:')
print(imapObj.login(email_id, pswd))
imapObj.select_folder('INBOX', readonly=True)

UIDs = imapObj.gmail_search('cryptography') #for searching the mails related to the given key
UIDs = imapObj.search(['ALL']) #for searching all the mails
UIDs = imapObj.search(['SINCE 05-Jul-2018 ']) #i tried this but it is not working
print(UIDs)

您需要提供搜索词列表,例如:

UIDs = imapObj.search(['SINCE', '05-Jul-2018', 'BEFORE', '30-Jul-2018'])

最新更新