imaplib.error:搜索命令错误:BAD [b'无法解析命令']

Bob*_*fer 1 python imap imaplib python-3.x

代码:标题中出现错误,但我在这里没有看到问题

def test():
     imap_host = 'imap.gmail.com'
     imap_user = 'email'
     imap_pass = 'pass'

     imap = imaplib.IMAP4_SSL(imap_host)
     imap.login(imap_user, imap_pass)
     imap.select('"[Gmail]/All Mail"')
     message = imap.search(None, 'SUBJECT', "Verify your email")
     print(message)

test()
Run Code Online (Sandbox Code Playgroud)

这里有什么问题吗?

Max*_*Max 5

您的主题需要用引号引起来,并传递给服务器。您只是为了Python而引用它,而不是为了传输。

您正在发送SEARCH SUBJECT verify your email(看起来像三个损坏的命令)而不是SEARCH SUBJECT "Verify your email".

尝试imap.search(NONE, 'SUBJECT', '"Verify your email"')

请注意字符串内的双引号。