Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Searching for working Sendmail

by cosmicperl (Chaplain)
on Feb 16, 2009 at 11:07 UTC ( [id://744037]=perlquestion: print w/replies, xml ) Need Help??

cosmicperl has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,
  I'm the past I've used a very simple bit of code to try and find out where sendmail is installed on a users server.
if (-e "/usr/bin/sendmail") { $sendmail = "/usr/bin/sendmail"; }#if if (-e "/usr/sbin/sendmail") { $sendmail = "/usr/sbin/sendmail"; }#if if (-e "/usr/lib/sendmail") { $sendmail = "/usr/lib/sendmail"; }#if if (-e "/var/qmail/bin/qmail-inject") { $sendmail = "/var/qmail/bin/qmail-inject"; }#if
As you can see it simple tests for files in known places, assuming if they have qmail installed then they are using it over sendmail.
  As you've probably guessed, although this works it often breaks. I'd like to replace this code with something that actually tests the binaries.
What is the best way of doing this. At first I thought:-
my $return = `/usr/lib/sendmail --help`;
But sendmail doesn't seem to have a --help, and this would only test the binary is there, and not that it's actually working.
  Does anyone know the best way to do this? Is the only way to actually try and send a mail and see if the result is 'EX_OK'.
if ( system( '/usr/lib/sendmail -t ...' ) eq 'EX_OK' ) { ... }#if
Is there a safe way to test and get 'EX_OK' without actually sending out mail?


Update: Maybe 'sendmail -bv'?
Update2: I'm currently thinking:-
unless ( system( '/usr/lib/sendmail -bv' ) ) { ### OK }#unless

Replies are listed 'Best First'.
Re: Searching for Sendmail
by holli (Abbot) on Feb 16, 2009 at 11:12 UTC
    perl -e 'print `whereis sendmail`;'

    Of course I was looking on CPAN first but there seems to be no File::WhereIs or the like.


    When you're up to your ass in alligators, it's difficult to remember that your original purpose was to drain the swamp.
      Maybe 'which' would be better. It does have a cpan module

        "which" (and, according to the perldoc, File::Which) will only look in directories in your $PATH, whereas "whereis" will also find binaries which are not in your path.

        All dogma is stupid.
      But more importantly. We still have the problem of detecting which of the returned list is actually working. They may have several copies or Sendmail or Qmail installed and only one working.

Re: Searching for Sendmail
by Bloodnok (Vicar) on Feb 16, 2009 at 13:00 UTC
    If it's a server on which sendmail has been installed via a package manager, why not, at least as a first step, consult the package manager or its' installation database e.g. on a Solaris box,
    grep ' f .*sendmail ' /var/sadm/install/contents
    (the whitespace is important) ??

    I know similar can be done on DRS, HP & Linux - but, not being as familiar with their package managers, I ought'nt provide too much detail (coz it'll probably be wrong and thus, at the very least, misleading)

    A user level that continues to overstate my experience :-))
Re: Searching for working Sendmail
by McD (Chaplain) on Feb 16, 2009 at 14:33 UTC
    Update: Maybe 'sendmail -bv'?

    Not a great idea - for starters, "" is a valid domain name, this mail will try to deliver. Consider also that even if you send mail to an invalid address it will generate a "bounce" or failure notice, and some poor admin somewhere is going to have to do something with those.

    If you're going to send test messages, at least send them to an account you monitor - this way, not only will you know it's working, you'll be the only victim if it runs amok, which is much nicer than victimizing some other random address.

      Sorry but I had to down vote you for that. Here is the -bv flag from sendmail man:-
      -bv Do not collect or deliver a message. Instead, send an email r +eport after verifying each recipient address. This is useful for test +ing address rewriting and routing configurations.
        I'll take that downvote - that's what I get for posting before coffee first thing in the morning. :-)

        BUT - "sendmail -bv" still sends mail. A DSN is sent back to the user who ran the command - and that address is even less clear! Probably just $USER from whatever environment spawned sendmail, but the manpage doesn't seem to say.

        Also, in generating the DSN, sendmail follows its delivery rules - so -bv to is going to generate network traffic (SMTP dialog up to "RCPT TO" it looks like), possibly directly to, depending on how the local sendmail is configured. Enough stuff like that in the logs never looks good.

        So how about I leave it at this: any time you're writing a program to send email, be extra careful about what addresses the mail is To and From, because when things go wrong you may never notice.

        And I get to learn something new about sendmail today. :-)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://744037]
Approved by ww
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-05-18 07:00 GMT
Find Nodes?
    Voting Booth?

    No recent polls found