#!/usr/local/bin/perl # # file: send_email.pl # $ISIP_HELP_FILE = <<__ISIP_HELP_HERE_FILE__; name: send_email synopsis: send_email -address email_address -subject descriptive_text -reply_to reply_address -file filename descr: this program sends email to the person specified in the email_address using the reply_to address given and the given subject with the given file as the body of the message example: send_email -address hamaker\@isip.msstate.edu -subject results of experiment 000000 on ISIP job submission applet -reply_to help\@isip.msstate.edu -file x.in options: -address: any email address that would be recognized by the isip mail system -subject: subject of mail -reply_to: reply-to field of email -file: file to use as body of message returns: the experiment number allocated to this experiment man page: none __ISIP_HELP_HERE_FILE__ # perl system modules # use File::Path; # define the program name # my @tmp = split(/\//, $0); $ISIP_PROG = pop(@tmp); # define command line options # $SE_OPT_ADDRESS = "-address"; $SE_OPT_SUBJECT = "-subject"; $SE_OPT_REPLY_TO = "-reply_to"; $SE_OPT_FILE = "-file"; # define command line arguments to all of the scripts # $SE_MAIL_COMMAND = "/usr/bin/rmail"; $SE_MAIL_FROM_FLD = "From: "; $SE_MAIL_TO_FLD = "To: "; $SE_MAIL_REPLY_FLD = "Reply-to: "; $SE_MAIL_SUBJECT_FLD = "Subject: "; # set default parameters # $SE_DEF_REPLY_TO = "bse_help\@isip.msstate.edu"; $SE_DEF_FROM = "bse_help\@isip.msstate.edu"; $SE_DEF_SUBJECT = "Bulldog Stock Exchange"; # load the command_line source # require "/ftp/pub/projects/bse/data/scripts/command_line.pm"; # parse the command line arguments # ($address, $subject, $reply_to, $filename) = command_line(0, $SE_OPT_ADDRESS, 1, $SE_OPT_SUBJECT, -1, $SE_OPT_REPLY_TO, 1, $SE_OPT_FILE, 1); # error checking of command line arguments # if (($address eq "") || ($filename eq "")) { isip_die("Must at least specify the recipients address and the file to use as the body of the message"); } # make sure the file exists and is readable # if (! -e $filename) { isip_die("filename not valid: $filename"); } if (! -r $filename) { isip_die("file not readable: $filename"); } # build the headers # if ($reply_to eq "") { $reply_to = $SE_DEF_REPLY_TO; } if ($subject eq "") { $subject = $SE_DEF_SUBJECT; } # start building the message # @message = (); # push on the To field # $str = join(' ', $SE_MAIL_TO_FLD, $address); push(@message, $str); # push on the subject line, reply-to line and From field # $str = join(' ', $SE_MAIL_FROM_FLD, $SE_DEF_FROM); push(@message, $str); $str = join(' ', $SE_MAIL_SUBJECT_FLD, $subject); push(@message, $str); $str = join(' ', $SE_MAIL_REPLY_FLD, $reply_to); push(@message, $str); # push on a blank line to indicate the beginning of the body # $str = ""; push(@message, $str); # copy in the file # open(fp_in, "$filename") or isip_die("could not open file: $filename"); @body = ; chop @body; push(@message, @body); close(fp_in); # open the mail process and send the mail # open(fp_pipe, "|$SE_MAIL_COMMAND $address") or isip_die ("could not open mail process"); # write each line of the message # foreach $line (@message) { print fp_pipe "$line\n"; } # close the pipe # close(fp_pipe); # exit gracefully # exit 1;