MongerMail
MongerMail is an object oriented module that will permit you to send e-mails from your
perl program with attachements, using sendmail.
MongerMail is a self contained module that does not require any othermodules to function. It
was written to be placed in your webspace with the program calling it. It does NOT have to
be installed on the server. Simply place it in the same directory as the program calling it.
MongerMail makes the process of sending attached documents (ASCII or Binary) from your Perl program
as easy as possible. It even allows you to easily specify HTML format for the outgoing mail.
First, fill in your e-mail address below, select a file, then send it to
yourself (we don't track your emails nor do we store them, this is a demo only). Once you have done that, you will be re-directed back to this page.
Version .02 is now in distribution. Minor changes in the coding have sent the benchmarks through
the roof! For example, we have tested monger mail with creating true attachments up to 19.5Mb (Yes, Mb, not Kb) in size.
Next, have look at the code below. This is the EXACT code that is used in the above demo. You
will see how unbelievably easy this is to use:
BEGIN TRANSCRIPT ================================================
#!/usr/bin/perl
#######################################################################
#
# MongerMail Demo Script
# ©2000, Perl Services
#
#######################################################################
#
# VARIABLES
%file = (
'1' => 'santaplane.jpg',
'2' => 'mongermail_demo.pl',
'3' => 'MongerMail.pm',
'4' => 'jim.jpg'
);
$admin_email = 'youremail@email.com';
$subject = 'Here is the file you requested';
$file_directory = '/usr/local/put/your/path/here';
$mail_program = "/usr/sbin/sendmail";
#
#######################################################################
#
&Parse;
$ScriptURL = "http://$ENV{'SERVER_NAME'}$ENV{'SCRIPT_NAME'}";
if($FORM{action} eq 'send') {
if(check_email($FORM{'email'})) {
use MongerMail;
my $mail = new MongerMail($mail_program);
$mail->to($FORM{email});
$mail->from($admin_email);
$mail->subject($subject);
$mail->content("Here is the demonstration file. It was mailed to you\nby utilizing MongerMail. Enjoy!");
$mail->attachment("$file_directory/$file{$FORM{filename}}");
$mail->send;
print "Content-type: text/html\n\n";
print "<BR><BR><BR><B>Thank You! The file has been mailed!</B>";
print "<BR><BR><BR><A HREF=\"http://www.perlservices.net/en/modules/MongerMail.shtml\"><B><<<< Back</B></A>\n";
} else {
print "Content-type: text/html\n\n";
print "<BR><BR><BR>OOPS! The e-mail address you entered was not in a valid email address format.";
print "<BR><BR><BR><A HREF=\"http://www.perlservices.net/en/modules/MongerMail.shtml\"><B><<<< Back</B></A>\n";
}
} else {
print "Content-type: text/html\n\n";
print "<BR><BR><BR>HEY! You attempted to call this program incorrectly.";
print "<BR><BR><BR><A HREF=\"http://www.perlservices.net/en/modules/MongerMail.shtml\"><B><<<< Back</B></A>\n";
}
exit;
sub check_email {
my($fe_email) = $_[0];
if($fe_email) {
if(($fe_email =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(\.$)/) ||
($fe_email !~ /^.+@\[?(\w|[-.])+\.[a-zA-Z]{2,3}|[0-9]{1,3}\]?$/)) {
return(0);
}
else {return(1)}
}
else {
return(0);
}
}
sub Parse {
local($name, $value, $buffer, $pair, $hold, @pairs);
if($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
} else {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$name =~ s/\n//g;
$name =~ s/\r//g;
$value =~ s/\n//g;
$value =~ s/\r//g;
#This section checks the value portion (user input) of
#all name/value pairs.
$value =~ s/<.+>?//g;
$value =~ s/\|//g;
$value =~ s///g;
$value =~ s/\s-\w.+//g;
$value =~ s/\0//g;
$value =~ s/\|//g;
$value =~ s/\\//g;
$value =~ s/system\(.+//g;
$value =~ s/grep//g;
$value =~ s/\srm\s//g;
$value =~ s/\srf\s//g;
$value =~ s/\.\.([\/\:]|$)//g;
$value =~ s/< *((SCRIPT)|(APPLET)|(EMBED))[^>]+>//ig;
#This section checks the value portion (from element name) of
#all name/value pairs. This was included to prevent any nasty
#surprises from those who would hijack you forms!
$name =~ s/<.+>?//g;
$name =~ s///g;
$name =~ s/^\s-\w.+//g;
$name =~ s/\0//g;
$name =~ s/\|//g;
$name =~ s/\\//g;
$name =~ s/system\(.+//g;
$name =~ s/grep//g;
$name =~ s/\srm\s//g;
$name =~ s/\srf\s//g;
$name =~ s/\.\.([\/\:]|$)//g;
$name =~ s/< *((SCRIPT)|(APPLET)|(EMBED))[^>]+>//ig;
$FORM{$name} = $value;
}
}
TD>
END TRANSCRIPT ===================================================
Download MongerMail.pm
|