Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I as trying ot make a simple script for a friend and it needs the ability to E-mail. I didn't to have to make him install the smtp server module so I decided to do the SMTP primitively. I can't figure out why the end of message dot is not working. This script was built for Activestate PERL. Does anyone know why it fails? It works from the a terminal connection to port 25. I can't figure it out.
#!/usr/bin/perl -w use IO::SOCKET::INET; ##CALL IP FROM SYSTEM## $ipconfig=`ipconfig`; $ipconfig=~/(.*IP.*\: )(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/; ##CHECK IF CURRENT IP IS SAME AS LAST IP## open(LAST,">last_ip_info.txt") or die "couldn't open last status file. + reason:$!\n"; @last=<LAST>; close(LAST); #if($last[0]eq$2) #{ # print 'current IP is the same as last IP'; #} #else #{ &mail_ip($2); #} ##PRINT OUT CURRENT IP## #print "IP\:"."$2".":IP\n"; open(LAST,">last_ip_info.txt") or die "couldn'topen last status file$! +\n"; print LAST "$2\n"; close(LAST); ################# ###SUBROUTINES### ################# sub mail_ip { my$ip=@_[0]; $smtpaddr='jman.g3d.com'; $mail_to='jrock@jman.g3d.com'; $mail_from='nehalspc@exario.net'; $hostname='nehal'; $sock = new IO::Socket::INET (PeerAddr => "$smtpaddr", PeerPort => 25, Proto => 'tcp', ); die "Socket could not be created. Reason: $!\n" unless $sock; while($line=<$sock>) { print "$line\n"; if($line=~/220/) { last; } } print $sock "helo $hostname\n"; print "helo $hostname\n"; while($line=<$sock>) { print "$line\n"; if($line=~/250/) { last; } } print $sock "MAIL FROM: $mail_from <$mail_from>\n"; print "MAIL FROM: $mail_from <$mail_from>\n"; while($line=<$sock>) { print "$line\n"; if($line=~/250/) { last; } } print $sock "RCPT FROM: $mail_to <$mail_to>\n"; print "RCPT FROM: $mail_to <$mail_to>\n"; while($line=<$sock>) { print "$line\n"; if($line=~/250/) { last; } } print $sock "DATA\n\n"; print "DATA\n\n"; while($line=<$sock>) { print "$line\n"; if($line=~/354/) { last; } } print $sock "\r\n.\r\n"; print ".\n"; while($line=<$sock>) { print "$line\n"; if($line=~/250/) { last; } } print $sock "QUIT\n"; print "QUIT\n"; while($line=<$sock>) { print "$line\n"; if($line=~/221/) { last; } } close ($sock); }

In reply to primitve SMTP by jdv79

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2023-09-25 10:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?