Python imaplib to gmail - Fetches only incoming emails

Viewed 64

I've a simply python script which basically tries to fetch all the email from a gmail account with the following - not great at all - code:

conn = imaplib.IMAP4_SSL('imap.googlemail.com')
conn.login(g_email, g_pass)
conn.select()

for i in range(1, highest_id_number):
    msg = conn.uid('fetch', str(i), '(RFC822)')[1][0]
    if msg:
        do_something_with_the_content

It turned out, that for some reason it fetches only the incoming emails, but not the outgoings.

How can I fetch outgoing email as well via imap?

Python: 2.7.18

Thank You.

1 Answers

Answering your question, outgoing emails cannot use IMAP. Remember that IMAP only works with Incoming connections. If you want to monitor the outgoing emails, I recommend using the SMPT protocols.

You can refer to the following documentation for more information:

My recommendation is to create a code for incoming emails using IMAP and one for outgoing emails SMTP.

Related