[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#47709: Some scripts way, way out of date



On Sat, 23 Oct 1999, Raul Miller wrote:

> However, I disagree with the thought process which suggests that Net::SMTP
> is in any way a replacement for sendmail.  The semantics are totally
> different (sendmail queues while Net::SMTP does not).

I think Net::SMTP should be used in all cases.  Whether it queues or not
is effectively an implementation issue.

If Sendmail (or any other SMTP daemon) is running on the system, then the
proper course of action is simply to use Net::SMTP to send to "localhost."
I commonly use the following syntax which works extremely well, although
obviously not as perfectly robust as it could be: 

	until($smtp = Net::SMTP->new("localhost")) {
	   sleep(int(rand 60) + 1);
	}

The actual delivery of mail to the final recipient is processed through
the queue just as if Sendmail had been invoked from the console and the
message piped to its STDIN as you suggest.

Ordinarily, if Sendmail is running as a daemon on the system, it is also
given the switches to process the queue periodically.  (It is possible to
do one and not the other, or to have one daemon to do each, but such
configurations are very rarely used.)  Note, however, that if Sendmail is
not running on the system so as to process the queue, then invoking
Sendmail from the command line as you recommend can have the effect of
putting the message into the queue forever, since nothing will ever take
it out and try to deliver it.

If you do not have an SMTP daemon on "localhost," then you can use
Net::SMTP to point to the smart remailer used on your network, which will
presumably also handle queue processing.  This configuration is impossible
by direct invocation of Sendmail.

You also have much greater control over the message format when you use
Net::SMTP than if you invoke Sendmail directly.  For example, since the
web server usually runs as a low-privilege user ("www-data" on Debian,
"nobody" by default), setting the "from" information with the "-f" switch
when invoking Sendmail directly will cause the annoying "Authentication
Warning: www-data set sender to whatever" text to be included if you
attempt to use a valid bounce address, as is good practice.

Finally, the use of Net::SMTP promotes independence of the Perl code from
mail program choices and even operating system choices.  Sending into the
"localhost" SMTP port with Net::SMTP provides a consistent interface
regardless of whether the system runs Sendmail, Smail, smtpd, or even
Microsoft Exchange on Windows NT!

> In most (not all) cases, for cgi work, you want to use a mail system
> which queues mail.  In most cases where you need to use a mail system
> which does not queue mail you also don't want that mail being delivered
> from inside a cgi program.

I agree here, but using Net::SMTP has several major advantages over
directly invoking Sendmail, and can fully preserve queue processing when
used appropriately.  Your points are well-taken and I would not recommend
Net::SMTP if it did require the sacrifice of queue processing.

-- Mike



Reply to: