Link to home
Start Free TrialLog in
Avatar of compuad77
compuad77

asked on

Problem with Perl IO::Sockets script...incomplete output

Hi,
I have recently installed a script a few days ago... Auction Script
Got everything working except email.

I have spent the last three days going through the forums and trying solutions, but to no avail.

The problem I am having is that the mail portion (below) is sending incomplete emails to the smtp server.
This is the only script usine IO::Sockets on my system and is being a pain..

I am running a Windows 03 server, IIS 6, Perl 5.8x (latest version), PHP, etc.
I have many other perl scripts which email just fine.

The auction script shows that the mail is sent from the script, but it never arrives.
I run my own mail servers on two different servers that I have allowed relaying from the site, but the mail that gets to the mail servers is corrupt. One mail servers logs show the mail is complete, but doesn't show it conforms to RFC standards and has incomplete headers. The other mail server shows an error 0, the the script is sending the email in an improper format.  It looks like the mail server isn't getting anything after it requests data, but I am not that experienced with this type of problem.

My site with the auction script is still in development at the moment and I am lost?

I am open to suggestions ????

This is what's getting through to the mail server with the A-S Script ;

8.15.1.xxx [000003EC] Mon, 10 Jul 2006 10:30:46 -0400 Connected
8.15.1.xxx [000003EC] Mon, 10 Jul 2006 10:30:46 -0400 >>> 220-mail.myserver.com ESMTP Merak 7.5.2; Mon, 10 Jul 2006 10:30:46 -0400
8.15.1.xxx [000003EC] Mon, 10 Jul 2006 10:30:46 -0400 <<< HELO 8.15.1.xxx
8.15.1.xxx [000003EC] Mon, 10 Jul 2006 10:30:46 -0400 >>> 250 mail.myserver.com Hello 8.15.1.xxx [8.15.1.xxx], pleased to meet you.
8.15.1.xxx [000003EC] Mon, 10 Jul 2006 10:30:46 -0400 <<< MAIL FROM: info@realestate.net
8.15.1.xxx [000003EC] Mon, 10 Jul 2006 10:30:46 -0400 >>> 250 2.1.0 <info@realestate.net>... Sender ok
8.15.1.xxx [000003EC] Mon, 10 Jul 2006 10:30:46 -0400 <<< RCPT TO: compuad77@xxx.com
8.15.1.xxx [000003EC] Mon, 10 Jul 2006 10:30:46 -0400 >>> 250 2.1.5 <compuad77@xxx.com>... Recipient ok; will forward
8.15.1.xxx [000003EC] Mon, 10 Jul 2006 10:30:46 -0400 <<< DATA
8.15.1.xxx [000003EC] Mon, 10 Jul 2006 10:30:46 -0400 >>> 354 Enter mail, end with "." on a line by itself
SYSTEM [000003EC] Mon, 10 Jul 2006 10:30:46 -0400 Disconnected

There is nothing in the error logs, and the above are from the smtp's server logs.

Any Ideas would be appreciated.

Here is the subroutine causing my headache !

sub sendemail {
#---------------------------------------------------------------------------#
        my ($to,$subject,$from,$message) = @_;
 &send_error("COMMON::SENDMAIL\n\n\"To\" not sent to sendemail")      if ($to eq '');
 &send_error("COMMON::SENDMAIL\n\n\"Subject\" not sent to sendemail") if ($subject eq '');
 &send_error("COMMON::SENDMAIL\n\n\"From\" not sent to sendemail")    if ($from eq '');
 &send_error("COMMON::SENDMAIL\n\n\"Message\" not sent to sendemail") if ($message eq '');
        my $trash;
        if ($config{'mailhost'} ne '0') {
                eval('use IO::Socket; 1;') or &send_error("COMMON::SENDEMAIL\n\nIO::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.");
                my $remote;
                $remote = IO::Socket::INET->new("$config{'mailhost'}:smtp(25)");
                $remote->autoflush();
                print $remote "HELO $config{'mailhost'}\r\n";
                $trash = <$remote>;
                print $remote "MAIL FROM: $config{'mailfrom'}\r\n";
                $trash = <$remote>;
                print $remote "RCPT TO: $to\r\n";
                $trash = <$remote>;
                print $remote "DATA\r\n";
                $trash = <$remote>;
                print $remote "To: $to\nFrom: <$config{'mailfrom'}>\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\n";
  print MAIL "From: $config{'mailfrom'}\n";
  print MAIL "Subject: $subject\n\n";
 
  print MAIL "$message\n";
  print MAIL "\n";
  print MAIL ".\n";
 
                close MAIL;
        }
}
#---------------------------------------------------------------------------#
Avatar of clockwatcher
clockwatcher

Try changing these lines:

               print $remote "To: $to\nFrom: <$config{'mailfrom'}>\nSubject: $subject\r\n\r\n";
                print $remote $message;
                print $remote "\r\n.\r\n";
 
To:

               print $remote "To: $to\r\nFrom: <$config{'mailfrom'}>\r\nSubject: $subject\r\n\r\n";
               print $remote $message;
               print $remote "\r\n\r\n.\r\n";

The ending "." should have two CRLFs before it.  The other change was just for consistency sake.

 
And also since you're on windows, I think just using the standard "\n" would give you the proper line terminators on your IO::Socket.  Unless you've flipped the socket to binmode somewhere.  I don't think a standard IO::Socket->new does an automatic open to binmode.

Since you've already got the \r\n throughout your code, you might as well flip your filehandle to binmode just to make sure the "\r\n" isn't sending "\r\r\n" behind the scenes.

   $remote = IO::Socket::INET->new("$config{'mailhost'}:smtp(25)");
   binmode $remote;
   $remote->autoflush();



Avatar of compuad77

ASKER

Hi, I tried the suggestions above, but still no joy.
Could it be doing this because there is no Mime or Content Type headers in the message format ?

???

-Richard
Hi,
I don't think the script is sending everything the mail server needs;

Here is what is sent to the mail server from a working script on the same server;

8.15.1.218      [000016E0] Fri, 14 Jul 2006 09:24:22 -0400 Connected
SYSTEM          [00001184] Fri, 14 Jul 2006 09:24:22 -0400 Client session DNS server 67.28.119.82 issuing MX query for "gmail.com"
8.15.1.218      [000016E0] Fri, 14 Jul 2006 09:24:22 -0400 >>> 220-mail.compu-ad.net ESMTP Merak 7.5.2; Fri, 14 Jul 2006 09:24:22 -0400
8.15.1.218      [000016E0] Fri, 14 Jul 2006 09:24:22 -0400 <<< EHLO localhost.localdomain
8.15.1.218      [000016E0] Fri, 14 Jul 2006 09:24:22 -0400 >>> 250-mail.compu-ad.net Hello localhost.localdomain [8.15.1.218], pleased to meet you.
8.15.1.218      [000016E0] Fri, 14 Jul 2006 09:24:22 -0400 <<< MAIL FROM:<info@realestate-fsbo.net>
8.15.1.218      [000016E0] Fri, 14 Jul 2006 09:24:22 -0400 >>> 250 2.1.0 <info@realestate-fsbo.net>... Sender ok
8.15.1.218      [000016E0] Fri, 14 Jul 2006 09:24:22 -0400 <<< RCPT TO:<info@realestate-fsbo.net>
8.15.1.218      [000016E0] Fri, 14 Jul 2006 09:24:22 -0400 >>> 250 2.1.5 <info@realestate-fsbo.net>... Recipient ok
8.15.1.218      [000016E0] Fri, 14 Jul 2006 09:24:22 -0400 <<< DATA
8.15.1.218      [000016E0] Fri, 14 Jul 2006 09:24:22 -0400 >>> 354 Enter mail, end with "." on a line by itself
8.15.1.218      [000016E0] Fri, 14 Jul 2006 09:24:22 -0400 *** <info@realestate-fsbo.net> <info@realestate-fsbo.net> 1 876 00:00:00 OK
8.15.1.218      [000016E0] Fri, 14 Jul 2006 09:24:23 -0400 >>> 250 2.6.0 876 bytes received in 00:00:00; Message accepted for delivery
8.15.1.218      [000016E0] Fri, 14 Jul 2006 09:24:23 -0400 <<< QUIT
8.15.1.218      [000016E0] Fri, 14 Jul 2006 09:24:23 -0400 >>> 221 2.0.0 mail.compu-ad.net closing connection
SYSTEM          [000016E0] Fri, 14 Jul 2006 09:24:23 -0400 Disconnected
The content-type isn't required.   Nothing's really required within the DATA block.  It would run into problems if there was something malformed in the MAIL FROM:, RCPT TO:, or you're not ending your DATA correctly.  Pretty much the only places that you'd have problems.

You might try to add some debug prints.  Temporarily replace it with this:

        if ($config{'mailhost'} ne '0') {
                eval('use IO::Socket; 1;') or &send_error("COMMON::SENDEMAIL\n\nIO::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.");
                print "Content-type: text/html\n\n";   # make sure we're safe to write to the browser
        my $remote;
      binmode $remote;
                $remote = IO::Socket::INET->new("$config{'mailhost'}:smtp(25)");
                $remote->autoflush();
                print $remote "HELO $config{'mailhost'}\r\n";
                print $trash = <$remote>;
                print $remote "MAIL FROM: $config{'mailfrom'}\r\n";
                print $trash = <$remote>;
                print $remote "RCPT TO: $to\r\n";
                print $trash = <$remote>;
                print $remote "DATA\r\n";
                print $trash = <$remote>;
                print $remote "To: $to\nFrom: <$config{'mailfrom'}>\nSubject: $subject\r\n\r\n";
                print $remote $message;
                print $remote "\r\n\r\n.\r\n";
                print $trash = <$remote>;
                print $remote "QUIT\r\n";
      print $trash = <$remote>;
          }

If you can't get it to work, you could always replace that section of code with a mailer anyway.  Net::SMTP ought to be installed under a default ActiveState install.
It still seems to be doing the same thing.  I have replaced the code above as suggested.
I do have Net::SMTP and it is being used by another script on the same server.
Can you suggest how, where and what code to replace????
You have been a lifesaver so far......

Thanks
ASKER CERTIFIED SOLUTION
Avatar of clockwatcher
clockwatcher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You Are Great !

It works like a charm !

thanks again !