简体   繁体   English

如何使用Inbox.py通过Telnet发送电子邮件?

[英]How do I send an email over Telnet using Inbox.py?

I want to use Inbox.py to create a local SMTP server, and send an email from it through Telnet. 我想使用Inbox.py创建本地SMTP服务器,并通过Telnet从中发送电子邮件。

Since the repo lacks a full example, I found in the issues for the repo someone had specified a full example but I can't seem to get it working. 由于该回购缺少完整的示例,因此我在回购的问题中发现有人指定了完整的示例,但我似乎无法使其正常运行。

They specify this code: 他们指定以下代码:

"""
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)

But I'm unsure exactly what that is doing. 但是我不确定到底在做什么。 I just want to send an email over Telnet with SMTP commands. 我只想通过SMTP命令通过Telnet发送电子邮件。

If I telnet 0.0.0.0 4467 , it fails when I specify my data then enter . 如果我telnet 0.0.0.0 4467 ,则在指定数据时失败,然后输入. , stating: ,说明:

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])

You might consider using the telnetlib standard library specifically for this purpose. 您可能会考虑为此专门使用telnetlib标准库。

The issue here might be that handle() is unable to make sense of the ' subject: ' when you try and send mail with the manner in which telnet requires, particularly in regards to carriage returns that would normally follow it. 这里的问题可能是,当您尝试以telnet要求的方式发送邮件时, handle()无法理解' subject: ',尤其是通常在其后的回车方面。

Another thing you can try is to include ' subject ' in your def handle. 您可以尝试的另一件事是在def句柄中包含' subject '。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM