#!/usr/bin/perl # # 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 vars qw( %o ); use Mail::Sender; use Getopt::Std; my %rckeys = ( 'subject' => 's', 'from' => 'f', 'mailserver' => 'm', 'pause' => 'p' ); # Read defaults open( IN, "$ENV{HOME}/.mmrc" ); my( $line, $l, $r ); while( $line = ) { chomp( $line ); $line =~ s/#.*//; ( $l, $r ) = $line =~ /^\s*(\S+?)\s*=\s*(\S.*)/; $r =~ s/\s+$//; # Trim excess spaces if( $rckeys{ $l } ) { $o{ $rckeys{ $l } } = $r; }else{ die( "Unknown option '$l = $r' in .mmrc" ); } } close( IN ); getopts( 'hl:m:s:f:a:p:q', \%o ); my $msgfile = shift(); die( qq{ mm - Mass mailer Author: Steve Slaven - http://hoopajoo.net Usage: mm [-h] [-l maillist] [-s subject] [-m mailserver] [-t to list] [-q] [-f from] [-a file[,file,file]] [-p pause] messagefile -q is quiet -fs are required -l or -t are required, either messagefile can be - for stdin } ) if( $o{ h } ); # Validate for( qw( f s ) ) { die( "Option '$_' required" ) unless $o{ $_ }; } die( "No message file" ) unless $msgfile; $o{ p } = sprintf( '%01d', $o{ p } ) || '10'; # Parse address list my @adds; if( $o{ l } ) { open( IN, $o{ l } ) || die( "Couldn't open list file: $o{l} ($!)" ); chomp( @adds = ); close( IN ); } if( $o{ t } ) { push( @adds, split( /,/, $o{ t } ) ); } # Check that adds were given die( "No addresses found, use -t or -l" ) if scalar( @adds ) < 1; # Read message open( IN, $msgfile ) || die( "Couldn't open message file: $msgfile ($!)" ); my $msg; { local $/; undef $/; $msg = ; } close( IN ); # Status dump, unless quiet mode if( $o{ q } ) { # Sleep before send, allow ctl-C sleep( $o{ p } ); }else{ print qq| mm Mass Mailer Steve Slaven - http://hoopajoo.net Mail server : $o{m} From : $o{f} Message file : $msgfile LAST CHANCE TO STOP w/ CTL-C!!! $o{p} seconds before send... |; # Do pretty sleep $| = 1; while( $o{ p } > 0 ) { $o{ p }--; printf '%5d', $o{ p }; sleep( 1 ); print "\b" x 5; } print "\nSending to:\n"; } # Create our object my $m = Mail::Sender -> new( { smtp => $o{ m }, from => $o{ f } } ); # Send things if( $o{ a } ) { # Attach files die( "File attachment not implemented" ); }else{ # Just mailmsg for( @adds ) { print " $_\n" unless $o{ q }; $m -> MailMsg( { to => $_, subject => $o{ s }, msg => $msg } ) || warn( "Could not send: $Mail::Sender::Error" ); } }