使用 Python 中的 imaplib 在 Gmail 中创建草稿邮件
我想编写一个 python 模块,将数据发送到 G 邮件帐户中的草稿消息。大约两周前我写了一个脚本,使用 imaplib 完美运行。我的模块的简化示例如下。 (我已经为任何人创建了一个测试电子邮件地址来测试此脚本。)
import imaplib
import time
conn = imaplib.IMAP4_SSL('imap.gmail.com', port = 993)
conn.login('[email protected]', '123456aaa')
conn.select('[Gmail]/Drafts')
conn.append("[Gmail]/Drafts", '', imaplib.Time2Internaldate(time.time()), "TEST")
它使用了 .append 函数,但今天当我运行该模块时,它会产生以下错误:
Traceback (most recent call last):
File "C:/Windows/System32/email_append_test.py", line 6, in <module>
conn.append("[Gmail]/Drafts", '', imaplib.Time2Internaldate(time.time()), "TEST")
File "C:\Python26\lib\imaplib.py", line 317, in append
return self._simple_command(name, mailbox, flags, date_time)
File "C:\Python26\lib\imaplib.py", line 1060, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "C:\Python26\lib\imaplib.py", line 895, in _command_complete
raise self.error('%s command error: %s %s' % (name, typ, data))
imaplib.error: APPEND command error: BAD ['Invalid Command']
正如我之前所说,此模块之前工作过。它成功创建了正文中包含字符串“Test”的草稿消息。由于此脚本曾经有效,因此它似乎更有可能与 Google 对 G 邮件帐户 IMAP 功能所做的更改有关,但该错误似乎表明 APPEND 命令中存在错误。我已经在两台不同的计算机上测试了 python 脚本,以查看我的库文件是否已损坏,但仍然存在相同的错误。
另外,我正在使用Python 2.6。任何帮助表示赞赏。
I want to write a python module that sends data to a draft message in a G-mail account. I have written a script about two weeks ago that worked perfectly using imaplib. A simplified example of my module is below. (I have created a test email address for anyone to test this script on.)
import imaplib
import time
conn = imaplib.IMAP4_SSL('imap.gmail.com', port = 993)
conn.login('[email protected]', '123456aaa')
conn.select('[Gmail]/Drafts')
conn.append("[Gmail]/Drafts", '', imaplib.Time2Internaldate(time.time()), "TEST")
It utilized the .append function, but today when I run the module and it produces the following error:
Traceback (most recent call last):
File "C:/Windows/System32/email_append_test.py", line 6, in <module>
conn.append("[Gmail]/Drafts", '', imaplib.Time2Internaldate(time.time()), "TEST")
File "C:\Python26\lib\imaplib.py", line 317, in append
return self._simple_command(name, mailbox, flags, date_time)
File "C:\Python26\lib\imaplib.py", line 1060, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "C:\Python26\lib\imaplib.py", line 895, in _command_complete
raise self.error('%s command error: %s %s' % (name, typ, data))
imaplib.error: APPEND command error: BAD ['Invalid Command']
As I said before, this module worked before. It successfully created draft messages with the string "Test" in its body. Since this script used to work, it seems more likely that it has something to do with a change Google made to the G-mail accounts IMAP features, but the error seems to indicate an error in the APPEND command. I have tested the python script on two different computer to see if my library file was corrupt, but the same error remained.
Also, I am using Python 2.6. Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
conn.append
之前添加以下内容:然后将
conn.append
行更改为:Before the
conn.append
, add the following:Then change the
conn.append
line to read: