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

I've been using the following code for years. Suddenly it stopped working. Here is a sendmail test I'm running on the host account:

#!/usr/bin/perl -w BEGIN { open (STDERR, ">error.txt") || die("Sorry - cannot open error.txt"); } use CGI qw(:cgi-lib); use CGI::Carp qw(fatalsToBrowser); use strict; my($email_body, $sender, $mail_program, $email_to, $email_subject); $email_body="Surely CPC is not alone as a victim of this relatively ne +w behavior. \n"; $email_to='arthurdoyle1@aol.com'; $sender='cpc@meshingwithgears.us'; $mail_program = "/usr/lib/sendmail -f$sender -t"; open(MAIL,"|$mail_program") || die("Sorry - Cannot open mail program. +Please contact our website via E-mail or try again later."); print MAIL "Reply-to: $sender\n"; print MAIL "To: $email_to\n"; print MAIL "From: $sender\n"; print MAIL "Subject: $email_subject\n"; print MAIL "Content-type: text/plain\n\n"; print MAIL "$email_body"; close (MAIL); print "</BODY></HTML>";; exit;

Error.txt file returns this line: Mon Jan 30 14:37:09 2017 esender.cgi: Can't exec "/usr/lib/sendmail": No such file or directory at esender.cgi line 24.
Isn't sendmail part of the original PERL installation?
Trying for two weeks to resolve this with Host Support and so far, getting nowhere.

Replies are listed 'Best First'.
Re: PERL Sendmail Problem
by Corion (Patriarch) on Jan 30, 2017 at 20:05 UTC

    No, /usr/lib/sendmail is a program that either is installed on your host (and then you can maybe use it to send mail) or not (then you cannot use it for sending mail either).

    Maybe you want to use MIME::Lite, which (despite its message at the top) can and does send mail very well? It can use a sendmail binary or talk directly via SMTP to the receiving host.

      When I look up MIME::Lite I find this WAIT! message:

      MIME::Lite is not recommended by its current maintainer. There are a number of alternatives, like Email::MIME or MIME::Entity and Email::Sender, which you should probably use instead. MIME::Lite continues to accrue weird bug reports, and it is not receiving a large amount of refactoring due to the availability of better alternatives. Please consider using something else.

      I've had limited success with Mail::Mailer so I'll try to use that in my script. In the body, tried to esc a single quote (by '') and use \n for end of line, but these didn't work. Looks like simple text with CRLF works instead of \n. Haven't figured out how to use single quote -

      Thanks. It seems that sendmail module has been removed by my host. Are you saying that you don't see anything wrong with the script?
      Is there a security problem or PERL update that has resulted in obsoleting sendmail? I don't want to accuse my host of removing sendmail unless there is a good reason.

        To clarify, sendmail is not a part of Perl , nor is it distributed with perl. It is a separate application. Your script just happened to be accessing the separate application. Any obsolescence in sendmail would come from itself, not from Perl. That said, a quick web search for "security concerns with sendmail" shows that many people consider sendmail insecure.

        Rather than "accusing" your host, I would phrase it something like,

        /usr/lib/sendmail used to exist on the server, but now it seems to not exist (in that, I cannot execute it at that path, and I cannot find it elsewhere). Was its remove a deliberate action, or an oversight during an upgrade? If it's deliberate, what alternatives do you support?

        But before sending that message, I'd suggest looking for sendmail, and see whether it's really missing, or whether they just removed your permissions to execute it, or whether they moved it.

        And really, the best solution, rather than pestering your host, would be to follow corion's advice

        You can find out where sendmail is, information about it including whether you have permission to run it, and similar information about /usr/lib/sendmail, with commands like these:

        $ which sendmail /usr/sbin/sendmail $ ls -l /usr/sbin/sendmail -rwxr-xr-x 1 root wheel 243824 Jan 13 18:14 /usr/sbin/sendmail $ ls -l /usr/lib/sendmail ls: cannot access '/usr/lib/sendmail': No such file or directory

        You can get similar information by writing a script that uses the file test operators.

        — Ken

        It seems that sendmail module has been removed by my host. ... I don't want to accuse my host of removing sendmail unless there is a good reason.

        If the module is not there any more, it would seem to be reason enough to say it's been removed. ;-)


        Give a man a fish:  <%-{-{-{-<

Re: PERL Sendmail Problem
by FreeBeerReekingMonk (Deacon) on Jan 31, 2017 at 19:27 UTC
    If you have mailx on your server, why not switch to that? Here is an example (it also calls the mailx directly, without using any perl libraries... should you not want to use these) http://www.perlmonks.org/?node_id=1128801

    important: sendmail and mailx accept different parameters, so you can not drop-in replace sendmail with mailx. You need to rearrange some of the parameters...