Here is a working example in Perl. Read RFC 821 for the protocol. Unless you are familiar with socket.h and socket.c I would suggest using IO::Socket::INET as it is much more intuitive to use. Note Net::SMTP is a much better option than code like this simple example which is just to show how it works.

#!/usr/bin/perl -w use strict; use IO::Socket::INET; # see RFC 821 http://www.ietf.org/rfc/rfc0821.txt my $forged_from = 'hotmail.com'; my $from = 'nobody@hotmail.com'; my $to = 'smtp_test@hotmail.com'; my $msg = "Subject: Subject\n\nHello me!\n\nNew Line\nMore Lin +es\n"; my $server = 'xxxx.xxxx.net.au'; # SMTP SERVER my $port = 25; my $timeout = 10; my $sock = IO::Socket::INET->new( PeerAddr => $server, PeerPort => $port, Proto => 'tcp', Timeout => $timeout, ); unless ( $sock ) { die"ERR - Could not connect socket to $server on port $port"; } if ( my $server = <$sock>) { print "Got Handshake: $server"; dialog( $sock, "HELO $forged_from\015\012" ); dialog( $sock, "MAIL FROM: $from\015\012" ); dialog( $sock, "RCPT TO: $to\015\012" ); dialog( $sock, "DATA\015\012" ); dialog( $sock, "$msg\015\012.\015\012" ); dialog( $sock, "QUIT\015\012" ); } else { die "No handshake sent from SMTP server\n" } sub dialog { my ( $sock, $send ) = @_; print $sock $send; print "Sent: $send"; my $receive = <$sock>; die "Got no response to $send" unless $receive; print "Recv: $receive"; } __DATA__ Got Handshake: 220 xxxx.xxxx.net.au ESMTP Sendmail 8.11.6/8.11.6; Sat, + 20 Dec 2003 21:39:21 +1100 (EST) Sent: HELO hotmail.com Recv: 250 xxxx.xxxx.net.au Hello blah.blah.blah.blah.com.au [203.220.x +xx.xxx], pleased to meet you Sent: MAIL FROM: nobody@hotmail.com Recv: 250 2.1.0 nobody@hotmail.com... Sender ok Sent: RCPT TO: smtp_test@hotmail.com Recv: 250 2.1.5 smtp_test@hotmail.com... Recipient ok Sent: DATA Recv: 354 Please start mail input. Sent: Subject: Subject Hello me! New Line More Lines . Recv: 250 Mail queued for delivery. Sent: QUIT Recv: 221 Closing connection. Good bye.

cheers

tachyon


In reply to Re: perl socket mail by tachyon
in thread perl socket mail by hweefarn

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.