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

Basically I think bless-ing your socket as a Net::SMTP object will work, but have a look at the Net::SMTP->new method for some additional initialization that goes on.
use Net::SMTP; # create your own socket however you want my $sock = IO::Socket::INET->new(...); net_smtp_from_existing_socket($sock) or die "couldn't do it, sorry"; sub net_smtp_from_existing_socket { my $sock = shift; my $hello = shift; # the optional hello message bless $sock, 'Net::SMTP'; $sock->autoflush(1); # can set $sock->debug here if you want unless ($sock->response() == CMD_OK) { $sock->close(); return undef; } (${*$sock}{'net_smtp_banner'}) = $sock->message; (${*$sock}{'net_smtp_domain'}) = $sock->message =~ /\A\s*(\S+)/; unless ($sock->hello($hello || "")) { $sock->close(); return undef; } $sock; }
Alternatively, use Net::SMTP->new to create the socket - the returned object itself is an IO::Socket::INET object.