I'm having a strange problem with the following simple SMTP script. I am running it on my Win2000 workstation and it is trying to send mail through our Solaris server, which does have SMTP enabled for anonymous access.

The script is:
use strict; use Net::SMTP; my $SMTP_SERVER = "xxx.x.xx.xxx"; my $EMAIL_DOMAIN = "xxx-xx.xxxx.com"; my $mailFrom = "myname\@domain.com"; my $subject = "Test SMTP Message"; my $msg ="This is a test message."; my $mailaddr = $ENV{USER} . "\@" . $EMAIL_DOMAIN; my $smtp = Net::SMTP->new($SMTP_SERVER, Debug => 1); print STDERR "Couldn't connect to smtp server: $!\n" unless $smtp; $smtp->mail($ENV{USER}."\@".$EMAIL_DOMAIN); $smtp->to('me@domain.com'); $smtp->data("\n"); $smtp->datasend("From: $mailFrom\n"); $smtp->datasend("To: me\@domain.com\n"); $smtp->datasend("Subject: $subject\n"); $smtp->datasend($msg); $smtp->dataend(); $smtp->quit;
The debug statements I get back are:
Net::SMTP: Net::SMTP(2.16) Net::SMTP: Net::Cmd(2.19) Net::SMTP: Exporter(5.562) Net::SMTP: IO::Socket::INET(1.25) Net::SMTP: IO::Socket(1.26) Net::SMTP: IO::Handle(1.21) Net::SMTP=GLOB(0x1a72800)<<< 220 ESMTP xxx-xx.xxxx.com Sendmail 8.8. +8+Sun/SMI-S VR4 ready at Fri, 2 Apr 2004 13:12:58 -0500 (EST) Net::SMTP=GLOB(0x1a72800)>>> EHLO MY PC NAME Net::SMTP=GLOB(0x1a72800)<<< 250- xxx-xx.xxxx.com Hello xx.xx.xx.xxx, + pleased to meet you<br> Net::SMTP=GLOB(0x1a72800)<<< 250-EXPN Net::SMTP=GLOB(0x1a72800)<<< 250-VERB Net::SMTP=GLOB(0x1a72800)<<< 250-8BITMIME Net::SMTP=GLOB(0x1a72800)<<< 250-SIZE Net::SMTP=GLOB(0x1a72800)<<< 250-ONEX Net::SMTP=GLOB(0x1a72800)<<< 250-ETRN Net::SMTP=GLOB(0x1a72800)<<< 250-XUSR Net::SMTP=GLOB(0x1a72800)<<< 250 HELP Couldn't connect to smtp server: Bad file descriptor

My research into the 'bad file descriptor' message suggests that I'm getting it because $! has no value since I've already lost the connection to the server. I've talked to our Solaris administrator (since I don't know Unix) and he can't find anything in the SMTP log that even shows I made a connection or encountered any errors on that side. He looked at the data returned by my script and agrees that it does look like I am connecting to the server, then being disconnected for some unknown reason. He tried sending an POP3 email message from my workstation using Outlook and relaying through the Solaris server and it was successful (with no authentication used). We are also able to use telnet on my workstation to send an
smtp message. He doesn't know Perl, but because he is able to send mail through the server anonymously using these other methods, he thinks the fault must lie with the Perl script. This script works fine when I'm using a Windows 2000 server as my smtp server, but the Windows server is not authorized to run SMTP, so I've been told I need to get it working using the Solaris server.

I have tried every variation I can think of in the $smtp->mail(' ') line, since that's the first line sent to the mail server after the connection is established and I thought the problem might lie there. I have also tried adding the Helo and port parameters to the Net::SMTP->new line. I have tried specifying the smtp server name rather than the IP address. No matter what variations I try for the different values and addresses needed (and I've been working on this for 2 days now), I still get the same exact return code.

Does anyone have any suggestions as to what is going on or how I can get some better feedback from the Solaris server?

Thanks,
tiredcoder (really tired)

Edited by BazB fixed formatting, added code and readmore tags.


In reply to SMTP Connection Problem by tiredcoder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.