20.13. smtpd — SMTP (简单邮件传输协议) 服务器

源代码: Lib/smtpd.py


This module offers several classes to implement SMTP servers. One is a generic do-nothing implementation, which can be overridden, while the other two offer specific mail-sending strategies.

20.13.1. SMTPServer 对象

class smtpd. SMTPServer ( localaddr , remoteaddr )

创建新的 SMTPServer 对象,绑定到本地地址 localaddr 。它将视 remoteaddr 为上游 SMTP (简单邮件传输协议) 中继器。 localaddr and remoteaddr 应该为 (host, port) 元组。对象继承自 asyncore.dispatcher ,且因此将自身插入 asyncore 的实例化事件循环。

process_message ( peer , mailfrom , rcpttos , data )

引发 NotImplementedError exception. Override this in subclasses to do something useful with this message. Whatever was passed in the constructor as remoteaddr will be available as the _remoteaddr 属性。 peer 是远程主机的地址, mailfrom 是信封发起人, rcpttos are the envelope recipients and data is a string containing the contents of the e-mail (which should be in RFC 2822 格式)。

20.13.2. DebuggingServer 对象

class smtpd. DebuggingServer ( localaddr , remoteaddr )

Create a new debugging server. Arguments are as per SMTPServer . Messages will be discarded, and printed on stdout.

20.13.3. PureProxy 对象

class smtpd. PureProxy ( localaddr , remoteaddr )

Create a new pure proxy server. Arguments are as per SMTPServer . Everything will be relayed to remoteaddr . Note that running this has a good chance to make you into an open relay, so please be careful.

20.13.4. MailmanProxy 对象

class smtpd. MailmanProxy ( localaddr , remoteaddr )

Create a new pure proxy server. Arguments are as per SMTPServer . Everything will be relayed to remoteaddr , unless local mailman configurations knows about an address, in which case it will be handled via mailman. Note that running this has a good chance to make you into an open relay, so please be careful.