Comparing efficiency in sending mail

Sheila King sheila at spamcop.net
Sun Mar 25 12:08:28 EST 2001


Some time back, in response to a request about how to send mail using Python,
the following article was posted:

On Mon, 5 Feb 2001 23:24:35 -0800 (PST), <chris at onca.catsden.net> wrote in
comp.lang.python in article <mailman.981444758.4937.python-list at python.org>:

:import os
:
:f = os.popen ( "/usr/sbin/sendmail", "w" )
:
:f.write ( """\
:From: your address
:To: recipient address
:Subject: spam
:
:spam spam wonderful spam spam spam
:""" )
:
:
:If you dont have sendmail on your system, or some other MTA, then you can
:use smtplib to send it directly to an off-site MTA. I can get you some
:simple code for that, but the above is the preferred way.

My question is this:
Why is using os.popen and calling sendmail preferred over using the smtplib
module? Is it less overhead for the server? If so, why?

I have found the smtplib module very easy to use and understand. I was
telnetting into my webhost just now, and experimenting with some of the advice
given above, but first of all, exactly as typed above didn't work on my host.
I had to add the -t switch to the call to sendmail, like this:

f = os.popen("/usr/lib/sendmail -t", "w")

I know that the -t switch tells sendmail to get the recipient for the SMTP
envelop from the message headers. I've been experimenting over how to have
more control over the SMTP envelope. I was looking at some sendmail docs here:
http://www-wsg.cso.uiuc.edu/sendmail/tutorial/run/commandline.html
and tried using the -bs switch at a command line prompt, but had trouble with
"bare line feeds", since my host is really using qmail, and just has a
sendmail wrapper around qmail.

Anyhow, that last part is really off-topic here, as it is an issue with how to
use sendmail/qmail. I just wanted to point out, that using the smtplib module
is easier and gives me more control over the messages I send, and therefore
I'm curious as to why I would want to use popen to send to sendmail instead.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/






More information about the Python-list mailing list