使用Python的Gmail中IMAP的问题

2024-10-02 08:16:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我对python2.7中的IMAP有一个问题 出于测试目的,我创建了foobar306@gmail.com,密码为testing123testing 我跟随this tutorial并在我的Python Iteractive Shell中键入以下内容:

    Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import imaplib
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('foobar306@gmail.com', 'testing123testing')
mail.list()
# Out: list of "folders" aka labels in gmail.
mail.select("inbox") # connect to inbox.
>>> 

什么都没有发生,甚至错误消息也没有。 注意:我已经在Gmail中启用了IMAP 谢谢,-蒂姆

更新:针对此评论:

Did you do the next section after the code you quoted above? – Amber

我试过了:

^{pr2}$

但它还是什么也没做


Tags: the目的comyou密码mailthistutorial
1条回答
网友
1楼 · 发布于 2024-10-02 08:16:24

它似乎对我有用;我通过python API创建了一个sarnoldwashere文件夹:

>>> mail.create("sarnoldwashere")
('OK', ['Success'])
>>> mail.list()
('OK', ['(\\HasNoChildren) "/" "INBOX"',
'(\\HasNoChildren) "/" "Personal"',
'(\\HasNoChildren) "/" "Receipts"',
'(\\HasNoChildren) "/" "Travel"',
'(\\HasNoChildren) "/" "Work"',
'(\\Noselect \\HasChildren) "/" "[Gmail]"',
'(\\HasNoChildren) "/" "[Gmail]/All Mail"',
'(\\HasNoChildren) "/" "[Gmail]/Drafts"',
'(\\HasNoChildren) "/" "[Gmail]/Sent Mail"',
'(\\HasNoChildren) "/" "[Gmail]/Spam"',
'(\\HasNoChildren) "/" "[Gmail]/Starred"',
'(\\HasChildren \\HasNoChildren) "/" "[Gmail]/Trash"',
'(\\HasNoChildren) "/" "sarnoldwashere"'])
>>> mail.logout()
('BYE', ['LOGOUT Requested'])

它应该仍然存在于web界面中。(除非其他人同时删除它。)

编辑包括课程的全部内容,甚至包括我重新学习Python方法的枯燥部分:

^{pr2}$

相关问题 更多 >

    热门问题