### *** IMPORTANT *** ### ### *** Make sure the path to PERL above is correct *** ### #~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~# # # Program is copyright by Ranson's Scripts all rights reserved # Email - support@rlaj.com # # Package Name ------- smtp-mail.pm # Program Version ---- 1.0 # Configuration File - none # # No support for this program is available # Use at your own risk. # #~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~# # USAGE # # Requires SendMail.pm to be present # # &send_mail("MailTo|MailFrom|CC|BCC|Subject|FileName|MailBody"); # MailTo = Recipient email address # MailFrom = Sender email address # CC = Carbon Copy email address # BCC = Blind Carbon Copy email address/s # Subject = Subject of email # FileName = Path and filename of mail body file (optional) # MailBody = Body of email # Define Variables (usually in configuration file or in your script) # Enter the operating system for your server # Unix = '0' # NT = '1' #$operating_system = '1'; # IF THIS IS A WINDOWS SERVER, # you will need to define the SMTP server below #$Define_SMTP_Server = 'smtp.dtccom.net'; # If you are having trouble with the windows mail, # set the debug below to "1" #$Set_Debug = '0'; # Enter the path to the mail program, FOR UNIX ONLY #$mailprog = '/usr/sbin/sendmail'; ### *** :) *** ### sub send_mail { my ($mail) = @_; ($MailTo, $MailFrom, $CC, $BCC, $Subject, $FileName, $MailBody) = split(/\|/, $mail); if ($MailTo !~ /^[^@]+@([-\w]+\.)+[A-Za-z]{2,4}$/) { print "The Mail To email address is not formatted correctly. $MailTo"; exit; } if ($MailFrom !~ /^[^@]+@([-\w]+\.)+[A-Za-z]{2,4}$/) { print "The Mail From email address is not formatted correctly. $MailFrom"; exit; } if ($CC ne "" && $CC !~ /^[^@]+@([-\w]+\.)+[A-Za-z]{2,4}$/) { print "The CC Mail email address is not formatted correctly. $CC"; exit; } if ($BCC ne "" && $BCC !~ /^[^@]+@([-\w]+\.)+[A-Za-z]{2,4}$/) { print "The BCC Mail email address is not formatted correctly. $BCC"; exit; } $My_MailBody = ""; if ($FileName ne "") { open(MAIL_FILE, "$FileName") || &open_error("The mail body file can not be found with the path specified.
$FileName
Please check the path to the file."); @lines = ; close(MAIL_FILE); foreach $line(@lines) { $My_MailBody .= $line; } $My_MailBody .= $MailBody; }else{ $My_MailBody = $MailBody; } if ($My_MailBody eq "") { print "ERROR\n\n"; print "No Mail Body Was Found"; exit; } if ($operating_system eq "0") { &unix_mail; }else{ require "SendMail.pm"; &windows_mail; } } sub unix_mail { if (-e "c:\\") { print "You are on a Windows OS, please set the \$operating_system var to 1"; exit; } open (MAIL, "|$mailprog $MailTo") || &open_error("Can not locate Sendmail with the path given
$mailprog

You can run pathtest.pl to try and determine the path to sendmail. Or ask your system administrator."); print MAIL "Subject: $Subject\n"; print MAIL "To: $MailTo\n"; if ($CC ne "") { print MAIL "Cc: $CC\n"; } if ($BCC ne "") { print MAIL "Bcc: $BCC\n"; } print MAIL "From: $MailFrom\n\n"; print MAIL "$My_MailBody"; close (MAIL); $unix_print_back = $My_MailBody; } # End unix mail ### *** :) *** ### sub windows_mail { if (-e "/var") { print "You are on a Unix OS, please set the \$operating_system var to 0"; exit; } $sm = new SendMail("$Define_SMTP_Server"); if ($Set_Debug eq "1") { $sm->setDebug($sm->ON); }else{ $sm->setDebug($sm->OFF); } $sm->From("$MailFrom"); $sm->Subject("$Subject"); $sm->To("$MailTo"); if ($CC ne "") { $sm->Cc("$CC"); } if ($BCC ne "") { $sm->Bcc("$BCC"); } $sm->setMailBody("$My_MailBody"); if ($sm->sendMail() != 0) { print "Content-type: text/html\n\n"; print "
\n";
  print $sm->{'error'}."\n";
  exit -1;
 }
} # End windows mail

                        ### *** :) *** ###

sub open_error {
    local ($errorname) = @_;
	$system_error = $!;    
print <<"Close~//~Print";



Open Error



Oops!

$errorname.


System Error is: $system_error

Close~//~Print exit; } # End sub open_error ### *** :) *** ### my $var = '1';