【发布时间】:2015-04-08 16:31:31
【问题描述】:
我想使用 Inbox.py 创建一个本地 SMTP 服务器,并通过 Telnet 从它发送一封电子邮件。
由于 repo 缺少完整的示例,我在 repo 的问题中找到了某人 had specified a full example 但我似乎无法让它工作。
他们指定了这个代码:
"""
Proxy smtp to a starttls server with authentication, from a local
connection.
"""
from inbox import Inbox
from smtplib import SMTP
inbox = Inbox()
SMTP_HOST = 'mail.example.com'
SMTP_USERNAME = 'username'
SMTP_PASSWORD = 'password'
@inbox.collate
def handle(to, sender, body):
"""
Forward a message via an authenticated SMTP connection with
starttls.
"""
conn = SMTP(SMTP_HOST, 25, 'localhost')
conn.starttls()
conn.ehlo_or_helo_if_needed()
conn.login(SMTP_USERNAME, SMTP_PASSWORD)
conn.sendmail(sender, to, body)
conn.quit()
inbox.serve(address='0.0.0.0', port=4467)
但我不确定这是在做什么。我只想使用 SMTP 命令通过 Telnet 发送电子邮件。
如果我telnet 0.0.0.0 4467,当我指定我的数据时它会失败然后输入.,说明:
error: uncaptured python exception, closing channel <smtpd.SMTPChannel connected 127.0.0.1:52779 at 0x10864f950> (<type 'exceptions.TypeError'>:handle() got an unexpected keyword argument 'subject' [/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/asyncore.py|read|83] [/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/asyncore.py|handle_read_event|449] [/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/asynchat.py|handle_read|158] [/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtpd.py|found_terminator|181] [/Users/Desktop/inbox.py|process_message|18])
【问题讨论】: