i have been trying to use socket to connect to SMTP server on port: 465 using SMTP TLS/SSL yes, using Perl, i need urgent help on making this request successfuly using socket,thank you.

use Socket; use MIME::Base64; my $cr = pack('H*','0D'); my $lf = pack('H*','0A'); my($username) = '***@gmail.com'; my($password) = 'mypass'; my($from) = '*******@gmail.com'; my($from_name) = 'Beanscake'; my($to) = 'emailto'; my($to_name) = 'name'; my($subject) = 'Test'; my($body) = "Test Line One.\nTest Line Two.\n"; my($mailServer) = 'smtp.gmail.com'; $main::SIG{'INT'} = 'closeSocket'; my$proto = getprotobyname('tcp'); my($port) = 465; my($serverAddr) = (gethostbyname($mailServer))[4]; socket(SMTP, AF_INET(), SOCK_STREAM(), $proto) or die("socket: $!"); $packFormat = 'S n a4 x8'; # Windows 95, SunOs 4.1+ #$packFormat = 'S n c4 x8'; # SunOs 5.4+ (Solaris 2) connect(SMTP, pack($packFormat, AF_INET(), $port, $serverAddr)) or die("connect: $!"); select(SMTP); $| = 1; select(STDOUT); # use unbuffemiles i/o. sendSMTP(1, "HELO local $cr$lf"); sendSMTP(1,"AUTH LOGIN $cr$lf"); sendSMTP(1,encode_base64($username).$cr.$lf); sendSMTP(1,encode_base64($password).$cr.$lf); sendSMTP(1, "MAIL FROM: <$from>$cr$lf"); sendSMTP(1, "RCPT TO: <$to>$cr$lf"); sendSMTP(1, "DATA $cr$lf"); sendSMTP(1, "To: $to_name<$to>$cr$lf"); sendSMTP(1, "MIME-Version: 1.0\r\n"); sendSMTP(1,"Content-Type: text/plain; charset=utf-8\r\n"); sendSMTP(1,"From: $from_name<$from>$cr$lf"); sendSMTP(1,"Subject: $subject $cr$lf\r\n"); sendSMTP(1, "$body $cr$lf"); sendSMTP(1,".$cr$lf"); sendSMTP(1, "QUIT $cr$lf"); close(SMTP); sub closeSocket { # close smtp socket on error close(SMTP); die("SMTP socket closed due to SIGINT\n"); } sub sendSMTP { my($debug) = shift; my($buffer) = @_; print STDERR ("> $buffer") if $debug; send(SMTP, $buffer, 0); recv(SMTP, $buffer, 200, 0); print STDERR ("< $buffer") if $debug; return( (split(/ /, $buffer))[0] ); }

In reply to help on socket to smtp on TLS/SSL by beanscake

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.