Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Net::SMTP works ... sometimes

by Anonymous Monk
on Mar 15, 2013 at 14:18 UTC ( #1023707=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, all!

I'm using Net::SMTP to send email via an institutional mail relay server. The good news is that my script works! The bad news is that it works only about 80% of the time. I cannot, for the life of me, figure out what's causing those 20% of cases to fail.

This is my Perl script:

#!/bin/perl print "Content-type:text/html\n\n"; use Net::SMTP; use strict; use warnings; use CGI; use CGI::Carp qw( fatalsToBrowser ); my %providers = ( 'ATT' => '@txt.att.net', 'Boost' => '@myboostmobile.com', 'Metro' => '@mymetropcs.com', 'Nextel' => '@messaging.nextel.com', 'Sprint' => '@messaging.sprintpcs.com', 'T-Mobile' => '@tmomail.net', 'Verizon' => '@vtext.com', 'Virgin' => '@vmobl.com' ); my $from = "[FROM_MAIL]"; my $q = new CGI; my $num = $q->param( 'number' ); # remove all non-digit characters from number $num =~ s/[^\d]//ig; # concatenate number with SMTP domain from %providers my $to = $num.$providers{ $q->param( 'provider' ) }; # remove all parentheses and dashes $to =~ s/[\(\)\-\s]//ig; my $title = $q->param( 'title' ); # remove extraneous whitespaces at beginning & end $title =~ s/^\s+|\s+$//g; my $hold = $q->param( 'item' ); my $body = "'$title'\n$hold\n--DO NOT RESPOND"; my $smtp = Net::SMTP->new( "[MAIL_RELAY]", Debug => 1 ); $smtp->mail( $from ); $smtp->to( $to ); $smtp->data(); $smtp->datasend( $body ); $smtp->dataend(); $smtp->quit; print "clearSMS( );";

Here's the error log for the message that was received:

Net::SMTP>>> Net::SMTP(2.29), referer: [URL] Net::SMTP>>> Net::Cmd(2.26), referer: [URL] Net::SMTP>>> Exporter(5.58), referer: [URL] Net::SMTP>>> IO::Socket::INET(1.28), referer: [URL] Net::SMTP>>> IO::Socket(1.28), referer: [URL] Net::SMTP>>> IO::Handle(1.24), referer: [URL] Net::SMTP=GLOB(0x3f6c6c)<<< 220 [MAIL_RELAY] ESMTP Fri, 15 Mar 2013 09 +:34:25 -0400, referer: [URL] Net::SMTP=GLOB(0x3f6c6c)>>> EHLO localhost.localdomain\r, referer: [UR +L] Net::SMTP=GLOB(0x3f6c6c)<<< 250-[MAIL_RELAY] Hello [IP], pleased to me +et you, referer: [URL] Net::SMTP=GLOB(0x3f6c6c)<<< 250-ENHANCEDSTATUSCODES, referer: [URL] Net::SMTP=GLOB(0x3f6c6c)<<< 250-PIPELINING, referer: [URL] Net::SMTP=GLOB(0x3f6c6c)<<< 250-8BITMIME, referer: [URL] Net::SMTP=GLOB(0x3f6c6c)<<< 250-SIZE, referer: [URL] Net::SMTP=GLOB(0x3f6c6c)<<< 250-DSN, referer: [URL] Net::SMTP=GLOB(0x3f6c6c)<<< 250-AUTH GSSAPI DIGEST-MD5 CRAM-MD5, refer +er: [URL] Net::SMTP=GLOB(0x3f6c6c)<<< 250-STARTTLS, referer: [URL] Net::SMTP=GLOB(0x3f6c6c)<<< 250-DELIVERBY, referer: [URL] Net::SMTP=GLOB(0x3f6c6c)<<< 250 HELP, referer: [URL] Net::SMTP=GLOB(0x3f6c6c)>>> MAIL FROM:<[FROM_EMAIL]>\r, referer: [URL] Net::SMTP=GLOB(0x3f6c6c)<<< 250 2.1.0 <[FROM_EMAIL]>... Sender ok, ref +erer: [URL] Net::SMTP=GLOB(0x3f6c6c)>>> RCPT TO:<[TO_MAIL]>\r, referer: [URL] Net::SMTP=GLOB(0x3f6c6c), referer: [URL] <<< , referer: [URL] 250 2.1.5 <[TO_MAIL]>... Recipient ok, referer: [URL] Net::SMTP=GLOB(0x3f6c6c), referer: [URL] >>> , referer: [URL] DATA\r, referer: [URL] Net::SMTP=GLOB(0x3f6c6c), referer: [URL] <<< , referer: [URL] 354 Enter mail, end with "." on a line by itself, referer: [URL] Net::SMTP=GLOB(0x3f6c6c), referer: [URL] >>> , referer: [URL] Henrik Ibsen A Concise Biography, referer: [URL] Net::SMTP=GLOB(0x3f6c6c), referer: [URL] >>> , referer: [URL] John Jay College, referer: [URL] Net::SMTP=GLOB(0x3f6c6c), referer: [URL] >>> , referer: [URL] Web Resource, referer: [URL] Net::SMTP=GLOB(0x3f6c6c), referer: [URL] >>> , referer: [URL] Access for John Jay users, referer: [URL] Net::SMTP=GLOB(0x3f6c6c), referer: [URL] >>> , referer: [URL] --DO NOT RESPOND, referer: [URL] Net::SMTP=GLOB(0x3f6c6c), referer: [URL] >>> , referer: [URL] ., referer: [URL] Net::SMTP=GLOB(0x3f6c6c)<<< 250 2.0.0 r2FDYPUP002139 Message accepted +for delivery, referer: [URL] Net::SMTP=GLOB(0x3f6c6c)>>> QUIT\r, referer: [URL] Net::SMTP=GLOB(0x3f6c6c)<<< 221 2.0.0 [MAIL_RELAY] closing connection, + referer: [URL]

...And this is from the one that didn't go through:

Net::SMTP>>> Net::SMTP(2.29), referer: [URL] Net::SMTP>>> Net::Cmd(2.26), referer: [URL] Net::SMTP>>> Exporter(5.58), referer: [URL] Net::SMTP>>> IO::Socket::INET(1.28), referer: [URL] Net::SMTP>>> IO::Socket(1.28), referer: [URL] Net::SMTP>>> IO::Handle(1.24), referer: [URL] Net::SMTP=GLOB(0x3f6c8c)<<< 220 [MAIL_RELAY] ESMTP Fri, 15 Mar 2013 09 +:34:00 -0400, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)>>> EHLO localhost.localdomain\r, referer: [UR +L] Net::SMTP=GLOB(0x3f6c8c)<<< 250-[MAIL_RELAY] Hello [IP], pleased to me +et you, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)<<< 250-ENHANCEDSTATUSCODES, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)<<< 250-PIPELINING, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)<<< 250-8BITMIME, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)<<< 250-SIZE, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)<<< 250-DSN, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)<<< 250-AUTH GSSAPI DIGEST-MD5 CRAM-MD5, refer +er: [URL] Net::SMTP=GLOB(0x3f6c8c)<<< 250-STARTTLS, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)<<< 250-DELIVERBY, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)<<< 250 HELP, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)>>> MAIL FROM:<[FROM_MAIL]>\r, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)<<< 250 2.1.0 <[FROM_MAIL]>... Sender ok, refe +rer: [URL] Net::SMTP=GLOB(0x3f6c8c)>>> RCPT TO:<[TO_MAIL]>\r, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)<<< 250 2.1.5 <[TO_MAIL]>... Recipient ok, ref +erer: [URL] Net::SMTP=GLOB(0x3f6c8c)>>> DATA\r, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)<<< 354 Enter mail, end with "." on a line by +itself, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)>>> Edgar Allan Poe A Concise Biography, refe +rer: [URL] Net::SMTP=GLOB(0x3f6c8c)>>> John Jay College, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)>>> Web Resource, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)>>> Access for John Jay users, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)>>> --DO NOT RESPOND, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)>>> ., referer: [URL] Net::SMTP=GLOB(0x3f6c8c)<<< , referer: [URL] 250 2.0.0 r2FDY0fZ001443 Message accepted for delivery, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)>>> QUIT\r, referer: [URL] Net::SMTP=GLOB(0x3f6c8c)<<< 221 2.0.0 [MAIL_RELAY] closing connection, + referer: [URL]

It appears that both are OK since "Message accepted for delivery" appears for both. However, only one of these two consistently comes through while the other consistently fails to be delivered. Any idea why Henrik Ibsen is coming through but Edgar Allan Poe gets lost on the way? Your help in reading these logs and pinpointing my error would be immensely appreciated.

Many thanks!

Comment on Net::SMTP works ... sometimes
Select or Download Code
Re: Net::SMTP works ... sometimes
by MidLifeXis (Prior) on Mar 15, 2013 at 17:13 UTC

    ISTR that if a '250 Message Accepted' response was given, the client's role was complete. At this point (in a previous life), I would go to the server's log files and start looking there for a reason.

    --MidLifeXis

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1023707]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (17)
As of 2014-08-27 13:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (238 votes), past polls