Search code examples
pythonemailimap

retrieve/search for emails using message ID through python IMAP


Is there a way to retrieve/search for emails using message ID through python IMAP programmatically.I want to extract attachments of the mail using message ID. Any help would be much appreciated.

Thank you


Solution

  • Thank you all for coming up to help me . I got it done finally. I was searching for a way to get the attachments of a mail with the given Message ID , I didn't know how to specify the search command with the message ID in the HEADER option or any other search option.

    I feel it can be helpful to someone like me who is new to IMAP and wants to similar task finally, I got it through this search command :

        #message id
        mid = '<CACDWeWHLGKbEHR-jMmx8da9QzkpPxC7Dizy6T4fm2V30JoHMuw@mail.gmail.com>'
    
        #the search command
        typ, data = imapSession.search(None, '(HEADER Message-ID "%s")' % mid)