小编Ran*_*ger的帖子

无法从收件箱以外的任何文件夹中检索gmail邮件(Python3问题)

更新:我的代码在python 2.6.5下工作但不是python 3(我使用的是3.4.1).

我无法在"所有邮件"或"已发邮件"文件夹中搜索邮件 - 我得到一个例外:

imaplib.error: SELECT command error: BAD [b'Could not parse command']
Run Code Online (Sandbox Code Playgroud)

我的代码:

import imaplib
m = imaplib.IMAP4_SSL("imap.gmail.com", 993)
m.login("myemail@gmail.com","mypassword")
m.select("[Gmail]/All Mail")
Run Code Online (Sandbox Code Playgroud)

使用m.select("[Gmail]/Sent Mail")也不起作用.

但是从收件箱中读取有效:

import imaplib
m = imaplib.IMAP4_SSL("imap.gmail.com", 993)
m.login("myemail@gmail.com","mypassword")
m.select("inbox")
...
Run Code Online (Sandbox Code Playgroud)

我使用mail.list()命令来验证文件夹名称是否正确:

b'(\\HasNoChildren) "/" "INBOX"', 
b'(\\Noselect \\HasChildren) "/" "[Gmail]"',
b'(\\HasNoChildren \\All) "/" "[Gmail]/All Mail"', 
b'(\\HasNoChildren \\Drafts) "/" "[Gmail]/Drafts"', 
b'(\\HasNoChildren \\Important) "/" "[Gmail]/Important"', 
b'(\\HasNoChildren \\Sent) "/" "[Gmail]/Sent Mail"', 
b'(\\HasNoChildren \\Junk) "/" "[Gmail]/Spam"', 
b'(\\HasNoChildren \\Flagged) "/" "[Gmail]/Starred"', 
b'(\\HasNoChildren \\Trash) "/" "[Gmail]/Trash"'
Run Code Online (Sandbox Code Playgroud)

我正在关注这些问题的解决方案,但它们对我不起作用:
imaplib …

python email gmail imaplib python-3.x

15
推荐指数
1
解决办法
1万
查看次数

标签 统计

email ×1

gmail ×1

imaplib ×1

python ×1

python-3.x ×1