import imaplib
def login_credentials():
return ("mail", "password")
def connect_imap():
m = imaplib.IMAP4_SSL("imap.gmail.com", 993)
details = login_credentials()
m.login(details[0], details[1])
return m
m = connect_imap()
ddate = '18-May-2018'
m.select("INBOX")
result, data = m.uid('search', None, '(SENTON %s)' % ddate)
print(data)