SMTP via pipes?

Thomas Wouters thomas at xs4all.net
Mon Jun 12 18:53:40 EDT 2000


On Tue, Jun 13, 2000 at 12:12:02AM +0200, Henning Schroeder wrote:

> 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.

Setting the buffersize passed to the popen2 call rediculously low (like 1)
will probably solve your immediate problem, but I'm not sure if it's the
ideal solution. It depends on exactly how you want to send mail, but
usually, starting 'sendmail -t' in a one-way pipe and passing it a message
is easier and more convenient than using -bs.

At least, if you just have a rfc822.Message or similar object, you can do:

sendmail = os.popen("/usr/lib/sendmail -t", "w")
sendmail.write(str(msg))

Of course, this is more of a 'fire and forget' solution: you don't have
extensive error checking on your mail. If you want something more elaborate,
including splitting up the list of recipients into sendmail-accepted
numbers, take a look at Sendmail.py in Mailman.

But if you just want this to work, 

> 	r, w = popen2(SENDMAIL)
 	r, w = popen2(SENDMAIL, 1)

should do it ;)

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list