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

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

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

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()

这里有什么问题?

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

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

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

注意字符串中的双引号。