Python Forum
Doesn't give me the payload of grouped emails when used IMAPClient. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Networking (https://python-forum.io/forum-12.html)
+--- Thread: Doesn't give me the payload of grouped emails when used IMAPClient. (/thread-21054.html)



Doesn't give me the payload of grouped emails when used IMAPClient. - pyseeker - Sep-12-2019

Hello,

I am trying to fetch the messages from our gmail inbox. So, there will be 1000s of messages sent to Inbox and are grouped for each 100 email messages. When I tried this method, the program only fetches some but not all and especially grouped email messages. How can I get all the messages from the email messages grouped as one email and how can I optimize my server.search in the code below ? Appreciate your thoughts ?

import email, time, sys
from imapclient import IMAPClient

with IMAPClient(HOST) as server:
    server.login(USERNAME, PASSWORD)
    server.select_folder('INBOX', readonly=True)

    messages = server.search(['ALL', 'UNSEEN'])
    for uid, message_data in server.fetch(messages, 'RFC822').items():
        email_message = email.message_from_bytes(message_data[b'RFC822'])
        print(email_message.get_payload(None, True))