A
A
Alexander2018-05-18 09:42:18
Python
Alexander, 2018-05-18 09:42:18

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)

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

I've been trying for 6 hours how to get all the sent letters from the mail.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Web Dentist, 2018-05-18
@kentuck1213

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)

Say it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question