2015-02-09 73 views
0

我想使用Inbox.py创建本地SMTP服务器,并通过Telnet从它发送电子邮件。如何使用Inbox.py通过Telnet发送电子邮件?

由于回购没有一个完整的例子,我发现在回购问题有人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]) 

回答

1

你可能会考虑使用telnetlib标准库专门用于此目的。

在这里的问题可能是handle()是无法使感“主题:”当你试着和其中Telnet要求,特别是关于通常会跟随它回车的方式发送邮件。

您可以尝试的另一件事是在您的def句柄中包含'主题'。