use strict; use warnings; use File::Basename; use Getopt::Long; use Net::SMTP; $| = 1; my $LINEENDING = qq{\r\n}; my $tz_offset; { # Change this for your timezone - in my case, currently CDT (GMT-0500) my %tz_offset_part = ( neg => 1, hr => 5, min => 0, ); $tz_offset = ( $tz_offset_part{neg} * -1 ) * ( 3600 * $tz_offset_part{hr} + 60 * $tz_offset_part{min} ); } my %auth; my $debug = 0; my $test = 0; my @to_address; my $from_address; my $subject = q{test message}; my $mail_server = q{localhost}; if ( scalar( grep( /^-/, @ARGV ) ) ) { my ($local_host); GetOptions( 'address:s' => \@to_address, 'sender:s' => \$from_address, 'server:s' => \$mail_server, 'un:s' => \$auth{un}, 'pw:s' => \$auth{pw}, 'debug+' => \$debug, 'test+' => \$test, 'withsubject:s' => \$subject, 'help' => \&help, ); @to_address = split( /,/, join( ',', @to_address ) ); if ( !$test ) { &help if ( !scalar(@to_address) ); &help if ( ( !defined($from_address) ) or ( !length($from_address) ) ); } } else { &help; } my $id; my $date_rfc822; my $boundary; { my $t = time; $id = gen_id( $t, $from_address ); $date_rfc822 = lt_2_rfc822( $tz_offset, $t ); $boundary = sprintf q{_%05d_%s}, $$, $id; } my @msg; # Add To, From, Message-ID, Date, Subject, and Content-Type headers push @msg, sprintf <; close $DF; $str = pack "u", $fc; } chomp $str; $str = sprintf <new( $mail_server, Debug => $debug, Port => $port, ) or die $!; my $dont_continue = 0; if ( defined $auth{un} ) { $smtp->auth( $auth{un}, $auth{pw} ) or $dont_continue++; } if ( !$dont_continue ) { $smtp->mail($from_address) or die $!; foreach (@to_address) { last if ($dont_continue); $smtp->to($_) or $dont_continue++; } } if ( !$dont_continue ) { $smtp->data() or $dont_continue++; foreach (@msg) { last if ($dont_continue); my $str = $_ . $LINEENDING; $smtp->datasend($_) or $dont_continue++; } if ( !$dont_continue ) { $smtp->dataend() or $dont_continue++; } } $smtp->quit; } # # Subroutines # sub help { printf <