popen(), sendmail: Success?

Thomas Bellman bellman at lysator.liu.se
Fri Apr 11 14:04:40 EDT 2003


Chuck Swiger <cswiger at mac.com> wrote:

> If you plan on sending any significant amount of mail, it is recommended 
>   that your code talk SMTP to port 25 and pipeline all of the messages 
> you need to send in one continuous stream.  If you fork a sendmail 
> subprocess for each message you send, that will create a wastefully huge 
> amount of system load.

If you write your application to talk SMTP directly, instead of
using the proper Unix API for sending mail (i.e, calling
/usr/lib/sendmail), you have a number of problems.

First, which machine should you talk SMTP with?  Localhost?  Not
portable.  There are lots of Unix machines which do not have any
MTA running listening to port 25.  Every machine I administrate
run Sendmail in queue mode only (except for the mail servers, of
course).  Thus, you need your application to be configurable for
the mail server to use.  If the system changes, and another mail
server should be used, the sysadmin might not remember, or know,
that that particular application must be reconfigured.  It
becomes even worse if it is an application where each user on the
machine has their own configuration, like Netscape or Mozilla...

Second, you better be prepared to queue the mails in case of
network or mail server problems and retry sending them at a later
time.  For example, when the latest Sendmail hole was announced,
I turned the mail server at work off for more than 12 hours
waiting for a patch from RedHat (after that time I decided I
couldn't wait for RedHat any longer and made my own patched
RPM).

If you talk SMTP directly, you run the risk of skipping any local
policy for sending email, like masquerading as a specific domain
instead of as the FQDN of the local host, or a number of other
settings.

There are many subtleties involved in the game of being, or
pretending to be, an MTA, many of which are not handled by the
smtplib Python module, and many of them are subject to local
policy, decided by the system administrator.  Sendmail, Postfix
and Qmail are written to take care of those; you are unlikely to
do a better job when writing an application whose primary purpose
*isn't* being an MTA.

I know many other sysadmins that run their systems similarly to
the way I run mine.  Any application that talks SMTP on their own
instead of calling /usr/lib/sendmail to do it, is considered
broken by us...

So, when you write any program that sends email, at *least* give
the option of configuring it to use /usr/lib/sendmail, and
preferably to use that by default.  It is at least as likely to
work out of the box as any other setting is.

I wouldn't mind if there were some standard Python API for
sending email, that did the right thing on all platforms,
though.


-- 
Thomas Bellman,   Lysator Computer Club,   Linköping University,  Sweden
"Adde parvum parvo magnus acervus erit"       ! bellman @ lysator.liu.se
          (From The Mythical Man-Month)       ! Make Love -- Nicht Wahr!




More information about the Python-list mailing list