0

Good day everyone, I'm working on a personal python small project here, trying to search messages with messages-id, but encounter error as below :

imaplib.error: SEARCH command error: BAD [b'Could not parse command']

this is a sample of the code :

line = '<ABCDefghIJKlmnOpqRS@mail.gmail.com>'
typ, data = mail.search(None, '(HEADER Message-ID "%s")' % line)
  • I think you should take out the `(` and `)` in the command and the `<` and `>` in the email address. – tdelaney Dec 13 '21 at 15:58
  • There's a question for getting a message from the Message-ID here, is this what you're looking for? https://stackoverflow.com/questions/3775667 – Shameen Dec 13 '21 at 16:01
  • () are not needed unless you need to group search terms. I would try to remove those first. Also turn on imaplib debugging to make sure you are sending what you expect. Also: what server are you connecting to? Some niche servers have terrible `SEARCH` implementations. – Max Dec 13 '21 at 16:34

0 Answers0