http://qs321.pair.com?node_id=19480

draco_iii has asked for the wisdom of the Perl Monks concerning the following question: (mail and news)

How do you properly use sendmail?

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How do you properly use sendmail?
by davorg (Chancellor) on Jun 23, 2000 at 14:07 UTC
Re: How do you properly use sendmail?
by spartacus9 (Beadle) on Aug 28, 2002 at 04:29 UTC
    I agree that using Mail::Send or Mail::Mailer is a cleaner solution. But if you really want to use sendmail, here's an example:
    open SENDMAIL, "| /usr/lib/sendmail -t -n -oi" or die $!; print SENDMAIL "From: user\@domain.com\n"; print SENDMAIL "To: $recipient\n"; print SENDMAIL "Subject: testing 123\n\n"; print SENDMAIL $msg_text; close (SENDMAIL);

      If you're going to do that then you should really check the return value from the call to open.

      open (SENDMAIL, "| /usr/lib/sendmail -t -n -oi") or die $!;
      --
      <http://www.dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

Re: How do you properly use sendmail?
by Juerd (Abbot) on Aug 05, 2003 at 06:56 UTC
    my $mailer = '/usr/sbin/sendmail -t -oi'; my $recipient = 'foo@bar.com'; my $message = '...'; open my $mailer, "|$mailer" or die $!; print $mailer <<"END" or die $!; From: user\@domain.com To: $recipient Subject: Testing 123 $message END close $mailer or die $!;
    Remember to make sure all data that goes into the headers (just $recipient in this example) is valid.
A reply falls below the community's threshold of quality. You may see it by logging in.