#! /usr/bin/env perl use warnings; use strict; my $MPACK = '/usr/bin/mpack'; my $SENDMAIL = '/usr/sbin/sendmail -t'; use Getopt::Long; my $TESTING = 0; my $to = ''; my $attachment = ''; my $content = ''; my $subject = ''; my $from = 'root@' . `hostname -f`; chomp $from; GetOptions( 'testing!' => \$TESTING, 'to=s' => \$to, 'attachment:s' => \$attachment, 'content:s' => \$content, 'subject:s' => \$subject, 'from=s' => \$from ); if ( $TESTING ) { print "testing => $TESTING\n" . "to => $to\n" . "attachment => $attachment\n" . "content => $content\n" . "subject => $subject\n" . "from => $from\n\n"; print "To: $to\n"; print "Subject: $subject\n"; print "From: $from\n"; print "\n"; print "$content\n"; } elsif ( $attachment ) { # we have to send via mpack qx( $MPACK -d '$content' -s "$subject" "$attachment" $to ); } else { # sending via standard sendmail open TEMP, "<$content" or die "Could not open $content for reading: $!"; $content = join( '', ); close TEMP; open SENDMAIL, "|$SENDMAIL" or die "Can not open $SENDMAIL: $!"; print SENDMAIL "To: $to\n"; print SENDMAIL "From: $from\n"; print SENDMAIL "Subject: $subject\n"; print SENDMAIL "Reply-to: $from\n"; print SENDMAIL "Content-type: text/plain\n\n"; print SENDMAIL $content; close SENDMAIL; }