Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

How to tell if a server has Sendmail?

by powerhouse (Friar)
on Sep 02, 2003 at 15:37 UTC ( [id://288340]=perlquestion: print w/replies, xml ) Need Help??

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

Is there a way for my script to know which "mailing" system is on a server?

I've done this,
$mailprog = '/usr/sbin/sendmail'; if (-d $mailprog) { # Installed } else { # not installed }
But that does not appear to be working. I know that it is installed, but it is not sending my mail which I do in the "Installed" place above.

Is there a different way? I am just giving this script to someone, whom I did not charge to build it, but I want to know who is using it and where. So it is sending me the server variables the first time it's ran, and only that time.

I would appreciate any tips or advice.

thx,
Richard

Replies are listed 'Best First'.
Re: How to tell if a server has Sendmail?
by jeffa (Bishop) on Sep 02, 2003 at 15:41 UTC
    -d asks if a file is a directory. Don't you mean -e instead?
    [jeffa@localhost]$ perl -le'print "yes" if -d "/usr/sbin/sendmail"' [jeffa@localhost]$ perl -le'print "yes" if -e "/usr/sbin/sendmail"' yes
    Also, consider using MIME::Lite, it's really nice. :) From the docs:
    Change how messages are sent ### Do something like this in your 'main': if ($I_DONT_HAVE_SENDMAIL) { MIME::Lite->send('smtp', "smtp.myisp.net", Timeout=>60); } ### Now this will do the right thing: $msg->send; ### will now use Net::SMTP as shown above

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      I'd think -x is a better test in this case.

      Also note that on Solaris sendmail is /usr/lib/sendmail. (If portability is a question. Other platforms may very well have it in other places.)

•Re: How to tell if a server has Sendmail?
by merlyn (Sage) on Sep 02, 2003 at 15:51 UTC
Re: How to tell if a server has Sendmail?
by Abigail-II (Bishop) on Sep 02, 2003 at 15:48 UTC
    Is there a way for my script to know which "mailing" system is on a server?

    The best way to find out is to contact your system administrator. Just the fact that there is a /usr/bin/sendmail doesn't mean that it's useable - if there is no correct sendmail configuration file, mail may not work, or not work corrrectly. It also might not be the correct sendmail, some systems have it in /usr/lib or /usr/sbin.

    Abigail

Re: How to tell if a server has Sendmail?
by Limbic~Region (Chancellor) on Sep 02, 2003 at 15:50 UTC
    powerhouse,
    The title asked how to tell if Sendmail is on a server, but the body of the node asked how to tell which "mailing" system was present. This could be far from trivial to figure out:

  • Is the service running on the standard port - 25? You could try telneting into port 25 or netstat -an | grep LISTEN
  • If you are able to telnet into port 25 - does the banner identify iteself? Do you trust what it says? Can you type help to query further?
  • What program shows up in the process table? ps -ef and the like
  • Are there more than one mail program on the same system? Perhaps configured to work in conjunction with each other on different ports
  • Is there a start up script/config file for Sendmail

    The list goes on and on. I would take jeffa's advice if you do not absolutely need to use Sendmail and make it as portable as possible.

    Cheers - L~R

Re: How to tell if a server has Sendmail?
by sgifford (Prior) on Sep 02, 2003 at 18:09 UTC

    If you just want to send mail to yourself, the most reliable way might be just connect to your own mail server via port 25 and send the mail that way. It would fail on a system that was only online periodically, but would succeed on any permanently connected system.

    It sounds like you want your program to send mail to you without the user knowing it. That's not a good way to get users of your software to trust you. You might find it preferable and more reliable to just include a request to mail you in the program's documentation, or request permission before sending the mail, at which point you can ask the user about their mail system.

Re: How to tell if a server has Sendmail?
by blue_cowdawg (Monsignor) on Sep 02, 2003 at 16:06 UTC

        Is there a way for my script to know which "mailing" system is on a server?

    Besides asking your system administrator as Abigail suggests you could open a socket to port 25 on the machine in question, see if something answers and look at the banner. Sendmail (for instance) depending on how your SysAdmn has configured it will give you something like:

        ]$ telnet localhost 25 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. 220 myhost.com ESMTP Sendmail 8.12.5/8.12.5; Tue, 2 Sep 2003 12:02:58 +-0400
    Keep in mind some folks modify the sendmail.cf file to obfuscate the fact that sendmail is running on the host as well as which version of sendmail. YMMV.


    Peter L. Berghold -- Unix Professional
    Peter at Berghold dot Net
       Dog trainer, dog agility exhibitor, brewer of fine Belgian style ales. Happiness is a warm, tired, contented dog curled up at your side and a good Belgian ale in your chalice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (1)
As of 2024-04-25 05:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found