我正在尝试使用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)
答案 0 :(得分:0)
您需要提供搜索字词列表,例如:
UIDs = imapObj.search(['SINCE', '05-Jul-2018', 'BEFORE', '30-Jul-2018'])