#!/usr/bin/perl -w # # Copyright (c) 2002 Steve Slaven, All Rights Reserved. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, # MA 02111-1307 USA # use strict; use Mail::Sender; use Getopt::Std; my %o; getopts( 'h:t:f:s:S:m:F:', \%o ); my $VERSION = 0.01; die( qq{ testmailer v$VERSION Author: Steve Slaven - http://hoopajoo.net Uses Mail::Sender Usage: $0 [-h] [-t TO] [-f FROM] [-s SUBJECT] [-S SMTP-SERVER] [-m MESSAGE] [-F FILES] -h This help message -t TO The TO mail address, required -f FROM The from address to be listed, defaults to user\@host -s SUBJ The email subject, if not passed defaults to "Test message" -m MSG If passed this will be used as the mail message, if not it will read STDIN for the mail message -S SERV The address of the mail server to use -F A comma separated list of files to include with the message as attachments } ) if( $o{ h } || ! $o{ t } ); # Now fill opts, %o has the options and will be full of all options # during regular script execution $o{ S } = $o{ S } || 'localhost'; $o{ s } = $o{ s } || 'Test Message'; chomp( $o{ f } = $o{ f } || $ENV{ USER } . '@' . `hostname` ); my @files = split( /\s*,\s*/, $o{ F } ) if $o{ F }; print qq{ Server: $o{S} To: $o{t} From: $o{f} Subject: $o{S} }; print " Files: " . join( ', ', @files ) . "\n\n" if @files; $o{ m } = $o{ m } || read_stdin(); my $sender = new Mail::Sender { smtp => $o{ S }, from => $o{ f } }; if( @files ) { print "Sending with files...\n"; $sender->MailFile( { to => $o{ t }, subject => $o{ s }, msg => $o{ m }, file => \@files } ); }else { print "Sending message...\n"; $sender->MailMsg( { to => $o{ t }, subject => $o{ s }, msg => $o{ m } } ); } sub read_stdin { my $acc; print "Enter message, press CTL-D to end\n"; $acc .= $_ while ; return( $acc ); }