I am using imaplib to get the number of emails received in a mailbox on specific dates and it works great but I would like to take it further and use variables to select the date range (with SINCE and BEFORE) and print the number of daily emails received since a chosen starting date until today in a a loop.
However I am already getting a error message when replacing the BEFORE date with today's date variable:
from datetime import date,timedelta
today = date.today()
tdate = today.strftime("%d-%b-%Y")
obj = imaplib.IMAP4_SSL('imap.gmail.com', 993)
obj.login('xxx@gmail.com', 'password')
obj.select('Inbox')
('OK', ['50'])
gmail_count = obj.search(None,'(SINCE "28-Aug-2020" BEFORE "tdate")')
values = gmail_count[1][0]
replaced = values.decode("utf-8").replace(" ", ",")
replaced.count(",") + 1
error: SEARCH command error: BAD [b'Could not parse command']
Is there a way to avoid this?