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

Hello, I am trying to use this simple sendmail script to send myself an e-mail. The script prints out "Success!" but the e-mail never arrives. Any ideas as to what could be wrong?

#!/usr/bin/perl print "Content-type:text/html\n\n"; $mailprog = '/usr/sbin/sendmail'; open(MAIL,"|$mailprog -t") or die "cannot open sendmail"; print MAIL "To: my\@email.address\n"; print MAIL "From: senders\@email.address\n"; print MAIL "Subject: this is the subject line\n\n"; print MAIL "these are the contents of the e-mail\n"; close(MAIL); print "Success!"; exit 1;

I have double-checked for typos in my e-mail address, and I am certain that the path to sendmail is correct.

Replies are listed 'Best First'.
Re: sendmail script
by GrandFather (Saint) on Feb 20, 2006 at 23:17 UTC

    I don't know about problems in the code as you presented it. But if it were me, I'd be using Mime::Lite for that job. The code would look something like (untested):

    use MIME::Lite; my $msg = MIME::Lite->new( From =>'senders@email.address', To =>'my@email.address', Subject =>'this is the subject line', ); $msg->send ();

    Update: remove bogus quoting pointed out by ikegami


    DWIM is Perl's answer to Gödel

      You introduced an error.

      From =>'senders\@email.address', To =>'my\@email.address',

      should be

      From =>'senders@email.address', To =>'my@email.address',

      or

      From =>"senders\@email.address", To =>"my\@email.address",
Re: sendmail script
by stonecolddevin (Parson) on Feb 20, 2006 at 23:19 UTC
    For one, you aren't using strict, that will catch a lot of the errors this script may be throwing.
    For another, i don't think you need to escape the email addresses in double quotes. check the mail account from which you are sending the mail to see if you are getting any return emails saying something like, "Recipient can not be found" or "does not exist".
    I'd also take a look at MIME::Lite and Mail::Sender
    meh.
Re: sendmail script
by spiritway (Vicar) on Feb 21, 2006 at 02:41 UTC

    I don't see anywhere where you actually send the message. As for your "Success!" message, it will print that regardless of what happens, unless your program dies.

      The line that says close (MAIL) should make the e-mail send.

        OK, maybe I'm looking at the wrong module, but when I checked out Email::Send, I got this information:

        use Email::Send; send Sendmail => $message;

        Otherwise, the information for Mail::Sendmail gives me:

        use Mail::Sendmail; %mail = ( To => 'you@there.com', From => 'me@here.com', Message => "This is a very short message" ); sendmail(%mail) or die $Mail::Sendmail::error; print "OK. Log says:\n", $Mail::Sendmail::log;

        It seems to me that there must be some sort of "send" instruction.

        If you're not using any modules, then perhaps you need to configure sendmail. And if you're not using a module, perhaps doing so would make your life easier.