in reply to Sendmail problems

You might do better to use Net::SMTP, which avoids the whole issue of forking to a (possibly insecure) sendmail.

If you are married to the open, what is the error message?


Remember, when you stare long into the abyss, you could have been home eating ice cream.

Replies are listed 'Best First'.
Re: Re: Sendmail problems
by peterr (Scribe) on Oct 03, 2003 at 03:41 UTC
    You might do better to use Net::SMTP, which avoids the whole issue of forking to a (possibly insecure) sendmail.

    I don't know how many changes there would be, being a Perl novice. Also, I use the "NMS" FormMail.pl, which runs SENDMAIL just fine, but they may have used their own modules. Sendmail is used twice in the Perl script, and it all worked perfectly on a Unix box, but there have been many changes since moving the website (Linux box). Looking at the code, all the sendmail does it is heap of PRINT comands. Would SMTP be the same, so all I would have to change is the "open" function ?? I guess I'd better find out if the SMTP module runs on the website firts though. :)

    If you are married to the open, what is the error message?

    That's the trouble, even with the shebang line as

    #!/usr/bin/perl -wT

    there is no error message, the script just stops. I have a PRINT just before the 'open' and a PRINT right after, and it just sits there. Here is diehtml

    sub diehtml { print start_html('Error processing order'), @_, end_html(), "\n"; exit 1; }

    Thanks,

    Peter

      I think that there is no error message because your $! is being reset by the unlink. Using Net::SMTP, you would replace various of the prints with methods from Net::SMTP:

      (where ... == the rest of the line) open (SENDMAIL ...) ==> $smtp=new Net::SMTP("localhost"); print SENDMAIL "HELO ..." ==> (implicit) print SENDMAIL "MAIL ..." ==> $smtp->mail(...); print SENDMAIL "RCPT ..." ==> $smtp->to(...); print SENDMAIL "DATA" ==> $smtp->data(); print SENDMAIL "..." ==> $smtp->datasend(stuff); print SENDMAIL "." ==> $smtp->dataend(); print SENDMAIL "QUIT" ==> $smtp->quit();

      Note that your could replace the data/datasend/dataend chunk with a single data(@msg) call, if you build the text of the message into @msg.


      Remember, when you stare long into the abyss, you could have been home eating ice cream.
        I think that there is no error message because your $! is being reset by the unlink.

        Is there a method to reset my $! ?

        Using Net::SMTP

        Using a small test script, this appeared to work (after I got the SMTP server name right. :)

        Peter

      You might try Mail::Sender then. It can give you a tied "filehandle" that you can print the message into.

      use Mail::Sender; ... my $sender = Mail::Sender->new(); $sender->Open({to => ..., from => ..., subject => ..., ...}); local *SENDMAIL = $sender->GetHandle(); print SENDMAIL "Hello there\nThis is the message!"; close SENDMAIL;

      Jenda
      Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
         -- Rick Osborne

      Edit by castaway: Closed small tag in signature

Re: Re: Sendmail problems
by peterr (Scribe) on Oct 04, 2003 at 02:49 UTC
    Hi,

    Can't work out why this is not sending me an email

    #!/usr/bin/perl -wT use Net::SMTP; $smtp = Net::SMTP->new('mailservername.net', Debug => 1, ); $smtp->mail('peter@mydomain.com'); $smtp->to("peter\@home.emailaddress.com"); $smtp->data(); $smtp->datasend("To: Peter\n"); $smtp->datasend("\n"); $smtp->datasend("test send\n"); $smtp->dataend(); $smtp->quit;

    There are no error messages, and no email received, yet when I used the "NMS" FormMail.pl on the same domain (my feedback form), I got an email in one minute. Any method to debug this ? We have Perl 5.006001 if that makes a difference.

    Peter