Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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 my $forged_from = ''; my $from = ''; my $to = ''; my $msg = "Subject: Subject\n\nHello me!\n\nNew Line\nMore Lin +es\n"; my $server = ''; # 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 ESMTP Sendmail 8.11.6/8.11.6; Sat, + 20 Dec 2003 21:39:21 +1100 (EST) Sent: HELO Recv: 250 Hello [203.220.x], pleased to meet you Sent: MAIL FROM: Recv: 250 2.1.0 Sender ok Sent: RCPT TO: Recv: 250 2.1.5 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.



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

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?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2023-09-24 03:53 GMT
Find Nodes?
    Voting Booth?

    No recent polls found