SMTP via pipes?
Henning Schroeder
hschroeder at gmx.net
Mon Jun 12 18:12:02 EDT 2000
Hello,
I have some users who don't have a local SMTP server running although
sendmail is available. All mail has to be sent via pipes. When you
call sendmail with the -bs parameter you can talk to sendmail like you are
connected to a smtp-server. So thought I write the below attached
wrapper. Unfortunately it doesn't run :-(
Can anybody help or give any hints how pipes behave and why it doesn't
work that way? Your help is very appreciated.
Henning
# Module pipesmtp.py
import smtplib
from popen2 import popen2
SENDMAIL = "/usr/lib/sendmail -bs"
class SocketDummy:
def __init__(self, file):
self.file = file
self.send = self.file.write
self.close = self.file.close
class FileDummy:
def __init__(self, input, output):
self.ifile = input
self.ofile = output
self.read = self.ifile.read
self.readline = self.ifile.readline
self.write = self.ofile.write
def close(self):
self.ifile.close()
self.ofile.close()
class SMTP(smtplib.SMTP):
def connect(self, host="doesnt_matter", port=0):
r, w = popen2(SENDMAIL)
self.file = FileDummy(r, w)
self.sock = SocketDummy(self.file)
(code, msg) = self.getreply()
if self.debuglevel > 0 : print "connect:", msg
return (code, msg)
if __name__ == "__main__":
s = SMTP()
print s.connect() # this works
print s.help() # here it hangs
print s.quit()
More information about the Python-list
mailing list