#!/usr/local/bin/perl =head1 NAME mailfiles - General purpose command line mailer supporting attachments =head1 SYNOPSIS B =head1 REQUIRED OPTIONS =over 4 =item -f from Specifies the from email address as I. =item -t to Send the mail to I, where I is one or more email addresses. Multiple addresses should be comma separated and quoted if spaces or special shell characters appear in the addresses. =back =head1 OPTIONAL ARGUMENTS =over 4 =item -c cc Copy one or more email addresses specified by I. Multiple email addresses must be comma separated and need to be quoted if spaces or special shell character appear in them. =item -d Convert all specified file attachments to DOS I format before attaching. Note that the attached files are modified if this option is specified. This is only meaninful if the attached files are text files in UNIX format and the message is being sent to a DOS/Windows client. =item -h smpt_host Use I as the mail server. Defaults to the B corporate mail server if not specified. =item -m message Put the text specified in I in the sent message body. Needs to be sent quoted from the shell if whitespace or special characters appear in it. =item -r reply_to Set the reply to address to I. =item -s subject Set the message subject to I. =item -u Convert all specified file attachments to UNIX newline format before attaching. Note that the attached files are modified if this option is specified. This is only meaninful if the attached files are text files in DOS/Windows format and the message is being sent to a UNIX client. =item file ... File(s) to be sent as attachments. =back =head1 AUTHOR Me =cut use strict; use Mail::Sender; use Getopt::Std; use XXX::File::TextConvert; # DOS/UNIX file conversions use vars qw/$opt_c $opt_d $opt_f $opt_h $opt_m $opt_r $opt_s $opt_t $opt_u/; my $mail_opts = { smtp => 'XXX.XXX.XXX.XXX', msg => ' ' }; my $message; my $from; my $to; my $cc; my $subject; sub parse_opts { getopts("c:df:h:m:r:s:t:u"); die "Required -f (from) value missing.\n" if (!defined($opt_f)); die "Required -t (to) value missing.\n" if (!defined($opt_t)); die "Only one of -d or -u makes sense.\n" if ($opt_d && $opt_u); $mail_opts->{from} = $opt_f if ($opt_f); $mail_opts->{smtp} = $opt_h if ($opt_h); $mail_opts->{to} = $opt_t if ($opt_t); $mail_opts->{subject} = $opt_s if ($opt_s); $mail_opts->{msg} = $opt_m if ($opt_m); $mail_opts->{cc} = $opt_c if ($opt_c); $mail_opts->{replyto} = $opt_r if ($opt_r); if (scalar(@ARGV) > 0) { unix_to_dos(@ARGV) if ($opt_d); # You write this dos_to_unix(@ARGV) if ($opt_u); # You write this $mail_opts->{file} = join(',', @ARGV); } } sub send_mail { my $sender = new Mail::Sender() or die "Can't create mail sender object: $!\n"; defined($mail_opts->{file}) ? $sender->MailFile($mail_opts) : $sender->MailMsg($mail_opts); } parse_opts(); send_mail(); exit 0;