How to get sent mail (Imap)?

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)

Error:
imaplib.error: command SEARCH illegal in state AUTH, only allowed in states SELECTED

6 hours I how to get all sent mail messages.
June 5th 19 at 21:16
1 answer
June 5th 19 at 21:18
Solution
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)


CaIIs it
Yes it is, Thanks!. and where you found this code ? you can link to. - brook.Dare commented on June 5th 19 at 21:21
Is glued code , searched resources 15 , unfortunately I do not remember where I found the key point. - Randy_Beier commented on June 5th 19 at 21:24
, Like this - Randy_Beier commented on June 5th 19 at 21:27

Find more questions by tags Python