#!/usr/bin/perl -s # # Author : Premson P. R. # Code : To Send Mail Along With Attachments. use MIME::QuotedPrint; use MIME::Base64; use Mail::Sendmail 0.78; $path="/usr/users/compaq/prem/test"; %mail = ( SMTP => '10.4.11.104', from => 'Premson ', to => 'compaqco@globaltrustbank.com', subject => 'Test Attachment', ); $boundary = "====" . time() . "===="; $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; foreach $VAL (@VAL) { $file_msg = "$ARGV[0]"; $file_att1 = $ARGV[1]; $file_att2 = "$ARGV[2]"; open(FILENAME, "$file_msg") or die "message: $!"; binmode F; undef $/; $message = encode_qp(); close(FILENAME); if($file_att1 eq "") { print "Null file detected in file_att1 : $file_att1\n"; } else { open (FONE, "$path/$file_att1") or die "Cannot read $file_att1: $!"; binmode FONE; undef $/; $mail{body} = encode_base64(); close FONE; } if($file_att2 eq "") { print "Null file detected in file_att2 : $file_att2\n"; } else { open (FTWO, "$path/$file_att2") or die "Cannot read $file_att2: $!"; binmode FTWO; undef $/; $mail2 = encode_base64(); close FTWO; } ############# One Attachment ################# if($file_att1 eq "") { if($file_att2 ne "") { die "\n"; else { $boundary = '--'.$boundary; $mail{body} = <