in reply to Pass a socket to a Net:SMTP object

Just a thought ...

Wouldn't it be cleaner to subclass Net::SMTP, and add the methods you need ?

     "A fanatic is one who redoubles his effort when he has forgotten his aim."—George Santayana

Replies are listed 'Best First'.
Re^2: Pass a socket to a Net:SMTP object
by sheepfunk (Initiate) on Jun 10, 2008 at 16:07 UTC
    You guys rock! blessing is the key! So basically I'm testing a socket to see if it's good, and then sending mail if its good like this: my $sock = new IO::Socket::INET->new(PeerPort => 25, PeerAddr => 'PEERADDR', Proto => 'tcp', LocalAddr => 'LOCALADDR' ) or die "Can't bind : $@\n"; $sock->recv($_, 2048); if(/^220/) { print "Connection OK!\n"; bless $sock, 'Net::SMTP'; $smtp = $sock; } else { print "Connection BAD!\n"; exit 1; } $smtp->mail($mail_from); $smtp->recipient($rcpt_to); $smtp->data; $smtp->datasend("From: $from\r\n"); $smtp->datasend("To: $to\r\n"); $smtp->datasend("Subject: $subject\r\n"); $smtp->datasend("\r\n"); $smtp->datasend("$body\r\n"); and so far (as of 5 minutes ago) it seems to be working! If there is something totally wrong with this please let me know, otherwise, thanks so much for the information!