Hi,
I have an old and normally very reliable piece of code that sends mail via smtp. Currently a customer is having trouble with it: after it connects to the socket, it hangs while trying to read the first line. Using
ethereal, I can see that the mail server is indeed sending me the first line, "220 ... \r\n". Connecting manually with telnet to the same server/port works perfectly, and the beginning ethereal output for the telnet connection looks the same as the perl script session to me.
I'm at a loss as to what could cause this. If it's a firewall or something like that, I think it would block the whole connection. I think a firewall would also block my manual telnet test.
I have two questions, really:
1. Can anyone think of a cause or explanation for this?
2. Do you think that rewriting my code to use IO::Socket might help?
This is a stripped down version of my code to illustrate what it does:
my $smtp = '167.206.5.250';
# part 1, connect to server:
use Socket;
my $proto = (getprotobyname('tcp'))[2];
my $port = (getservbyname('smtp', 'tcp'))[2];
my $smtpaddr = pack('C4',$1,$2,$3,$4) if ( $smtp =~ /^(\d{1,3})\.(\d{1
+,3})\.(\d{1,3})\.(\d{1,3})$/ );
socket(S, AF_INET, SOCK_STREAM, $proto) or die("socket failed: $!");
connect(S, pack('Sna4x8', AF_INET, $port, $smtpaddr)) or die("connect
+failed: $!");;
# part 2, read first line:
local($oldfh) = select(S); $| = 1; select($oldfh);
while (my $line = <S>)
{
print "--> $line\n";
last;
}
Thanks,
Joe
P.S. I'm using perl 5.8.1 on windows, in case the version/os makes a difference here.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.