# # EDVMAIL 0.2 # use warnings; use strict; use Mail::Sender; use File::Slurp; use Getopt::Attribute; use Getopt::ArgvFile; our $to : Getopt(to=s); our $from : Getopt(from=s EDV); our $subject : Getopt(subject=s); our $password : Getopt(password=s xxxx); our $mode : Getopt(mode=s html); our @cc : Getopt(cc=s); our @mailfiles : Getopt(files=s); our @attachments : Getopt(attachments=s); our @lines : Getopt(lines=s); die "No recipient specified!\n" . usage() unless defined $to; die "No subject specified!\n" . usage() unless defined $subject; die "No message specified!\n" . usage() unless (@mailfiles or @lines); my ($br, $ctype); if ( $mode =~ /html/i ) { $br = "
"; $ctype = "text/html"; } else { $br = ""; $ctype = "text/plain"; } my $sender = new Mail::Sender { smtp => '192.168.1.23', from => "$from\@kvsaarland.de", authid => $from, authpwd => $password, } or die "Cannot create Mail::Sender Object: $Mail::Sender::Error\n"; $sender->OpenMultipart ({ to => $to, subject => $subject, cc => [@cc], boundary => "" }); $sender->Body({ encoding => 'ISO-8859-1', ctype=>$ctype }); $sender->Send('') if $br; if ( @lines ) { $sender->Send ( map { chomp; "$_$br\n" } @lines ) or die "$Mail::Sender::Error\n"; } if ( @mailfiles ) { $sender->Send ( map { map { chomp; "$_$br\n" } read_file ($_) } @mailfiles ) or die "$Mail::Sender::Error\n"; } $sender->Send('') if $br; if ( @attachments ) { $sender->Send ( "$br\n" x 2 ), $sender->Attach ( { file => $_ } ) for @attachments; } $sender->Close() or die "Message not sent: $sender->{'error_msg'}\n"; print "Message sent.\n"; sub usage { return <<'USAGE'; edvmail.pl - 0.2 Usage: edvmail -parameter [wert] Parameter: -fr(om) opt. Author (without "@domain", default: EDV) -to req. Recipient -cc * opt. CC-Adresses -s(ubject) req. subject -p(assword) opt. Password, default "xxxx" -fi(les) * opt. Textfiles that build the text for the Mail -a(ttachments) * opt. Well, attachments. -l(ines) * opt. Text of the mail -m(ode) opt. "text" or "html", default "html" Parameters with * can me specified multiple times. Example: edvmail -fr m.holzer -to p.balfie@kvsaarland.de -cc m.taller@kvsaarland.de -s "How ya doin'?" -l "Something funny" -l "in the attachment" -a c:\jokes.txt USAGE }