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":



  • 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.