sendmail.pl (this perlscript) is a replacement for the real
sendmail software.
Its use is for use at servers (or elsewhere), that shall not
have the real sendmail for e.g. security reasons.
It is not as convenient as the real sendmail, it can just
send email and knows no parameters, but it is a convenient
way to get mail running e.g. for cronjobs - even 3rd party
applications can use this, which was prooved by using
tallyman (opensource shopsystem).

It uses Net::SMTP to send mail off and you have to set your
own mailserver and mailserver-user to get it running.

It expects at least a "to:" or "from:"-line, "subject:" which
is optional, all caseinsensitive. If this is not the case,
the mailserver-user gets the mail to inspect this for error
reasons.
There's also the possiblity to log all mails being sent to a
logfile you can specify(only for debugging reasons!).
It has been used successfully for several months on multiple
hosts, now.
Adjust to your settings and check it out on the console giving
a to:, from, and a subject: -line (if you want), some text,too,
and close it with return, ctrl-d

If you have use for it, use it :)
if you have code improvements, post them :)
#!/usr/bin/perl -w # ###################################################################### +#### # + # # sendmail, a perl-replacement for the original, it just collects the + # # data, and sends them to the specified eMailserver. + # # diposition to enable mailing for servers, who don't have a dinosaur +:) # # + # # No relay by smtp possible with this script! + # # No commands the original knows are recognized! + # # + # # put it to /usr/lib/sendmail, the standard place for the original or + # # the place it is expected to satisfy other applications. + # # + # ###################################################################### +#### use Net::SMTP; # module which does the mailin +g # has to be installed use strict; my @textdata = <STDIN>; # fetch incoming data undef my $hclf; # variables initialised for us +e strict my $textdata; # other mys are spread over th +e script my $loop; my @loop; undef my $mail_to; undef my $mail_subject; undef my $mail_from; my $mail_text; ############################ # # # user setting start here: # $mailhost = "host.domain.where"; # the mailserver, which delive +rs mail $maileruser = "username\@domain.where"; # the user, who is allowed to +use the mailserver # the user, who gets errormess +ages, too #$hclf = "/tmp/sendmail.log" # file, where to pipe all mail +content at. # use only for debugging! # if used by cgi, webserver's +user needs # rights to write there (apach +e). #my $mdebug = "1"; # debug the module on stdout, +default value is "1" # higher values are possible b +ut not useful my $mdebug = "0"; # don't debug the module on st +dout # user settings stop here! # # # ############################ if ($hclf) { open (GUN,">>$hclf") || die "cant write to $hclf"; print GUN scalar localtime(); } undef my $counter; # init helpers, just to be saf +e undef my $body; foreach $textdata (@textdata) { print GUN $textdata if $hclf; if ($counter < 3) { $loop[$counter] = $textdata; # collect "To:", "From:" and + "Subject:" # "To:" and "From:" are requir +ed, # "Subject:" is optional, see +later } else { $body = $body . $textdata; # collect bodytext } $counter++; } print GUN "\n###################################\n" if $hclf; if ($hclf) { close (GUN) || die "cant close $hclf"; } undef my $count; for my $i (0 .. 2) { if ($loop[$i] =~ /to:\s*([\w\W]*)/i) { # case insensitive is required + here! $mail_to = $1; # to match all clients using this + :) $count++; } if ($loop[$i] =~ /subject:\s*([\w\W]*)/i) { $mail_subject = $1; $count++; } if ($loop[$i] =~ /from:\s*([\w\W]*)/i) { $mail_from = $1; $count++; } } if ( # cases, if mail is undelivera +ble (! $mail_to) or # if so, alarm defined $mailer +user (! $mail_from) ) { my $whereat = `/bin/uname -n`; chomp $whereat; $mail_to = $maileruser; $mail_from = "perlsendmail <$maileruser>"; $mail_subject = "perlsendmail has found an error at $whereat!"; $mail_text = "0: $loop[0]1: $loop[1]2: $loop[2]$body"; } else { # if ok, init remaining vars if ($count lt 3) { $mail_text = $loop[2] } $mail_text = $mail_text . $body; $mail_subject = "\n" if (! $mail_subject); # catch empty subjects eve +n not given # any other header informatin +should # be at the top of the $body } my $time = "Date: " . localtime(); chomp $mail_from; chomp $mail_to; chomp $mail_subject; my $smtp = Net::SMTP->new("$mailhost", Debug => $mdebug, ); $smtp->mail("$mail_from"); $smtp->to("$mail_to"); $smtp->data(); $smtp->datasend("From: $mail_from $time To: $mail_to Subject: $mail_subject $mail_text "); $smtp->quit; exit; # bye-bye, baby :)

In reply to sendmail.pl - a Sendmail replacement by khippy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.