Answer the question
In order to leave comments, you need to log in
How to get all sent emails (Imap)?
import imaplib
import email
M = imaplib.IMAP4_SSL("imap.gmail.com", 993)
M.login("[email protected]", "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
Answer the question
In order to leave comments, you need to log in
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)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question