reyjrar has asked for the wisdom of the Perl Monks concerning the following question:

so I've been looking at this for too long, and can't make sense of why its not working?
no, Net::SMTP and Mail::Send are not on this box and it takes forever to get modules installed on this box..

if($EMAILS) { socket(MAIL,PF_INET,SOCK_STREAM,getprotobyname('tcp')) +; connect(MAIL,sockaddr_in(25,inet_aton($MAILHOST))) || +die "$!\n";; select MAIL; $|++; select STDOUT; print MAIL "HELO mydoamain.net\r\n"; print "Emailing users: "; for(split(/,/,$EMAILS)) { print "$_, "; print MAIL "MAIL FROM: $from\n"; print MAIL "RCPT TO: $_\n"; print MAIL "DATA\n"; print MAIL "Subject: $subject\n\n"; print MAIL "$data\n"; print MAIL ".\r\n"; } print "done. \n"; print MAIL "QUIT\r\n"; close MAIL; }
$EMAILS is a comma delimited string of email addresses.. I've tried all sorts of combinations with \r and \n and can't seem to get it to work, the script acts as though its working, but it doesn't send me mail, the connections don't fail and no errors are thrown anywhere..
I tested the mail server by telnetting to it on port 25 and issuing the EXACT commands the script is and its working.. I'm kinda lost on this one..

I'm trying to avoid a pipe to sendmail directly being that this SHOULD work.

-brad..

Replies are listed 'Best First'.
(Guildenstern) Re: baffled by the sendmail..
by Guildenstern (Deacon) on Nov 04, 2000 at 00:46 UTC
    According to the RFC for SMTP (RFC 821), all commands must end with carriage return + linefeed, so it sounds like all of your commands should end in \r\n. The SMTP server should issue status messages along the way, so it may be a plus to check that everything is going as expected.

    Update: I just tried your code cut n' paste with my own server after adding the \r\n to all lines, and it worked like a charm.

    Guildenstern
    Negaterd character class uber alles!
RE: baffled by the sendmail..
by Fastolfe (Vicar) on Nov 04, 2000 at 01:05 UTC
    It would help immensely if you could provide the data the SMTP server is sending in response. (Reading from SMTP should work.) You aren't getting any errors because your script is functioning perfectly (well, almost; see below). The SMTP server is probably returning errors, however, but your script isn't reading any data from the socket, only sending it, so you'll never know.

    With respects to the newline thing, it may be simplest to just set, say, $/ = "\r\n"; and terminate your lines with $/ instead. To be honest, most MTA's tend to not care whether you use \n or \r\n.

    In addition, you may wish to spit out To: and From: headers in addition to your Subject: header. The MAIL FROM/RCPT TO stuff isn't really seen in the message itself.

Re: baffled by the sendmail..
by reyjrar (Hermit) on Nov 04, 2000 at 02:01 UTC
    thanks, got it working..
    I KNEW it was something right under my nose, just needed someone else to look at it.. :)

    -brad..