以下 Python 函数适用于 Outlook、gmail 和我的共享托管 exim 服务器,但通过 yahoo.com 发送邮件时返回此错误:
APPEND command error: BAD ['[CLIENTBUG] Additional arguments found after last expected argument']. Data: FHDJ4 APPEND inbox.sent "31-Aug-2016 12:30:45 +0100" {155}
作为比较,展望回报:
('OK', ['[APPENDUID 105 2] APPEND completed.'])
Gmail 返回:
('OK', ['[APPENDUID 14 2] (Success)'])
和进出口回报:
('OK', ['[APPENDUID 1472211409 44] Append completed (0.788 + 0.076 secs).'])
我的函数使用 imaplib2,传递给它的参数都是字符串,self.username 是发送电子邮件地址,如 address@domain.com
我的功能是:
def send_mail(self, to_addrs, subject, msgtext, verbose=False):
# build message to send
msg = email.message.Message()
msg.set_unixfrom('pymotw')
msg['From'] = self.username
msg['To'] = to_addrs
msg['Subject'] = subject
msg.set_payload(msgtext)
if verbose: print("Sending Mail:\n ", msg)
# connect and send message
server = self.connect_smtp()
server.ehlo()
server.login(self.username, self.password)
server.sendmail(self.username, to_addrs, str(msg))
server.quit()
print("Saving mail to sent")
sentbox_connection = self.imap_connection
print(sentbox_connection.select('inbox.sent'))
print(sentbox_connection.append('inbox.sent', None, imaplib2.Time2Internaldate(time.time()) , str(msg)))
我尝试用这一行生成 msg 变量:
msg = "From: %s\r\n" % self.username + "To: %s\r\n" % to_addrs + "Subject: %s\r\n" % subject + "\r\n" + msgtext
并使用 "" 而不是 None 像这样附加消息:
print(sentbox_connection.append('inbox.sent', None, imaplib2.Time2Internaldate(time.time()) , str(msg)))
你能告诉我我做错了什么吗?或者,如果雅虎有一种特殊的方式来处理我需要考虑的附加命令?
编辑:澄清一下,所有 smtp 服务器都可以发送邮件,但将发送的邮件附加到 inbox.sent 对雅虎来说失败