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; }