import imaplib
import email
M = imaplib.IMAP4_SSL("imap.gmail.com", 993)
M.login("myuser@gmail.com", "mypass")
M.select('Sent')
status, data = M.search(None, 'ALL')
print(data)
imaplib.error: command SEARCH illegal in state AUTH, only allowed in states SELECTED
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)