Python SMTPD Example

244 views
Skip to first unread message

tare...@gmail.com

unread,
Feb 26, 2006, 9:07:27 AM2/26/06
to python-eg
SMTPD is a module that has many classes from implementin a Mail Server
(SMTP Demon). One of these classes is SMTPServer

----------------------------------------------

from smtpd import *
import asyncore

class MyRelay(SMTPServer):
def process_message(self, peer, mailfrom, rcptto, data):
print "Message:", peer, mailfrom, rcptto, data
data = data + "[TAG]"

if __name__ == "__main__":
s = MyRelay(("127.0.0.1",25),("1.1.1.1",25))
try:
asyncore.loop()
except:
print "Bye Byeeeeeeeeee !!"
s.close()

---------------------------------------------------------------------------
References:
http://www.python.org/doc/lib/module-smtpd.html
http://pydoc.org/2.2.3/smtpd.html
http://www.koders.com/python/fidFCF970EF47E055C9BF1DA42F82858C538F739D13.aspx

tare...@gmail.com

unread,
Feb 26, 2006, 12:00:08 PM2/26/06
to python-eg
We have to use PureProxy instead of SMTPServer in order to deliver the
message to the outside (remote) server
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

from smtpd import *
import asyncore

class MyRelay(PureProxy):


def process_message(self, peer, mailfrom, rcptto, data):
print "Message:", peer, mailfrom, rcptto, data

data = data + "[Some TAG]"
PureProxy.process_message(self,peer,mailfrom,rcptto,data)

if __name__ == "__main__":
s = MyRelay(("127.0.0.1",25),("1.1.1.1",25))
try:
asyncore.loop()

except KeyboardInterrupt:
pass
s.close()

Reply all
Reply to author
Forward
0 new messages