Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: perl socket mail

by tachyon (Chancellor)
on Dec 20, 2003 at 10:50 UTC ( [id://316028]=note: print w/replies, xml ) Need Help??

in reply to perl socket mail

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.



Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://316028]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-16 14:59 GMT
Find Nodes?
    Voting Booth?

    No recent polls found