【问题标题】:How do I send an email over Telnet using Inbox.py?如何使用 Inbox.py 通过 Telnet 发送电子邮件?
【发布时间】: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])

【问题讨论】:

    标签: python email smtp telnet


    【解决方案1】:

    您可以考虑专门为此目的使用telnetlib 标准库。

    这里的问题可能是handle() 在您尝试使用 telnet 要求的方式发送邮件时无法理解“subject:”,尤其是在回车方面通常会跟随它。

    您可以尝试的另一件事是在您的 def 句柄中包含“subject”。

    【讨论】:

      猜你喜欢
      • 2018-02-15
      • 2012-03-14
      • 2021-02-11
      • 2013-10-17
      • 2016-05-15
      • 1970-01-01
      • 2012-12-20
      • 1970-01-01
      • 2011-06-02
      相关资源
      最近更新 更多