Greetings all,

A few weeks ago I posted on the (EA Forum) looking for a modification that would let me
continue to use EA on my small hobby site. My ISP (covad) switched to password authentication
for email. I thought that this must have been a problem for others, so someone must have a
script that would work with Blat. No sense reinventing the wheel. I can't be the only one
running Windows with Apache and a EA powered web site in the background on a home computer.
A few weeks went by and neither here or searching goggle could I find a "drop in" replacement
for the Sub: Send E-mail. Syntax problems. So I thought what the heck and took a stab at it
myself. Below is the new SUB: E-mail I wrote. This will let you send email using Blat with
authentacation. Here is how Blat is described on it's SourceFourge.net home page;
"Blat - A Win32 command line SMTP mailer. Use it to automatically eMail logs, the contents
of a html FORM, or whatever else you need to send."

Oh, one more thing. Blat is a little slower then the original EA script. Mostly because
it has to wait for authentication from the ISP before it can send the email.

Before we begin remember, if you do not need to authenticate before you can send email
there is no reason to install this. The original smtp in EA works great.

The first thing we need to do is install Blat. There are many different versions of blat,
we want Blat v2.2.2 full. You can download it from http://blat.net

It's about 100k in size. The only file you will need from the download package is blat.exe.
Place it in your cgi-bin folder. If you want to keep it in another location you can.
Change the new sub email to reflect it's location. Below are instructions for installing
blat. If you have no need please ignore it and skip down to the Namtog Note's.

Now open up a console, command prompt, or what some versions of windows call a ms-dos prompt.
Then change to the folder where you installed blat. For me it goes like this;
cd\ (press enter) # now in root directory
cd apache (press enter) # now in apache directory
cd cgi-bin (press enter) #now in cgi-bin


Now check to see if blat is OK by typing blat and then press the enter key. If it reads Blat
version yadda yadda yadda all is well. If not you are in the wrong folder.

Now install the preset values for blat. If your isp has a odd setup, like other then port 25
for email you will have to change this. See the doc file that came with blat. Type the
following exactly, including the spaces.
blat -install smtp.your.isp [email protected] - - - yourloginname yourpassword (press enter)


Let's check blat to make sure it works. Send a email to a yahoo or hotmail account. Any place
other then your ISP. First we will send a small email, then one with a attachment. Type;
blat - -to someplace.com -subject test -body yadda (press enter)

Now with a file, first create a new file with notepad, it can be empty, and place it in
your cgi-bin. Name it test.txt Now type;
blat test.txt -to someplace.com -subject filetest (press enter)


Ok, check your email, where you sent these two test emails, if both are there you are
more than 75% done.


Open up EA in your favorite editor and scroll down to the email configuration. Either
comment out or delete the following;


# Namtog Note: Delete or comment out the mail protocols below
# You need to assign either a mail program or
# a mail host so confirmation e-mails can
# be sent out.
# Leave one commented and one un commented.
#
# YOU NEED EITHER A MAIL PROGRAM
# $config{'mailprog'} = '/usr/lib/sendmail -t';
#
# OR YOU NEED A MAIL HOST (SMTP)


#$config{'mailhost'} = 'smtp.your.isp';
# Namtog Note: Delete or comment out the mail protocols above


Now just one more thing to do, replace the sub send email. Delete or comment out
the following original SUB: Send E-mail;


# Namtog Note: Delete or comment out the mail protocols below
# SUB: Send E-mail
# This is a real quick-and-dirty mailer that
# should work on any platform. It is my first
# attempt to work with sockets, so if anyone
# has any suggestions, let me know!
#
# Takes:
# (To, Subject, From, Message)


sub sendemail {
my ($to,$from,$subject,$message) = @_;
my $trash;
if ($config{'mailhost'}) {
eval('use IO::Socket; 1;') or &oops("IO::Socket could not be loaded by the


script. Please see the script documentation for details. It looks like this server is using

perl version $]. IO::Socket may not be included with versions of perl prior to 5.00404.");
#

don't cause errors on machines where IO::Socket is not available
my $remote;
$remote = IO::Socket::INET->new("$config{'mailhost'}:smtp(25)");
$remote->autoflush();
print $remote "HELO\r\n";
$trash = <$remote>;
print $remote "MAIL From:<$config{'admin_address'}>\r\n";
$trash = <$remote>;
print $remote "RCPT To:<$to>\r\n";
$trash = <$remote>;
print $remote "DATA\r\n";
$trash = <$remote>;
print $remote "From: <$from>\r\nSubject: $subject\r\n\r\n";
print $remote $message;
print $remote "\r\n.\r\n";
$trash = <$remote>;
print $remote "QUIT\r\n";
}
else {
open MAIL, "|$config{'mailprog'}"; print MAIL "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n\r\n$message\r\n\r\n"; close MAIL;
}
}
# Namtog Note: Delete or comment out the mail protocols above


Replace it with one of the two SUB: Send E-mail sections below. The first one should
work for almost everyone. If you have a problem with sending very, very, long emails
switch to the SUB: Send E-mail at the bottom of this add on. It creates a temp file
(message.txt) and is slower then the first SUB: Send E-mail listed here.

#-#############################################
# SUB: Send E-mail Namtog's Mailer for Blat V.2.2.0 full (2003.09.17)
# change (2003.11.6) removed temp file suggested by Tim Musson


# Takes:
# (To, Subject, From, Message)
sub sendemail {
my($to, $from, $subject, $message) = @_;
my($mail_program, $blat_string);
$mail_program = "Blat"; #location of blat change if needed
$mail_program =~ s/\//\\/g;
$blat_string = "- -t $to -i $from -s \"$subject\" -body \"$message\" -q";
system ("$mail_program", "$blat_string");


}
###############################################

Only if you are having problems with long emails use the SUB: Send E-mail below.


#-#############################################
# SUB: Send E-mail Namtog's Mailer for Blat V.2.2.0 (2003.09.17)


# Takes:
# (To, Subject, From, Message)
sub sendemail {
my($to, $from, $subject, $message) = @_;
my($mail_program, $temp_file, $blat_string);
$mail_program = "Blat"; #location of blat change if needed
$temp_file = "message.txt";
open(MAIL, ">$temp_file");
print MAIL "$message\n";
close MAIL;
$temp_file =~ s/\//\\/g;
$mail_program =~ s/\//\\/g; $blat_string = "$temp_file -t $to -i $from -s \"$subject\" -q";
system ("$mail_program", "$blat_string");
unlink $temp_file;
}
###############################################


That's it. Your done.
[email protected]
Hosted by www.Geocities.ws

1