开发者

Using socks5 proxy with Net::SMTP

I开发者_如何学C would like to use Net::SMTP with dynamic socks proxy. IO::Socket::Socks is aware of socks but how it should be used with net::smtp?


I figured it out, but it includes hack that may or may not work with future version of Net::SMTP :

use Net::SMTP;
use Net::SOCKS;
my $socks = new Net::SOCKS(socks_addr=>$shost,socks_port=>$sport, protocol_version=>5) or die $!; 
my $socksfd = $socks->connect(peer_addr=>$smtp_server,peer_port=>25);
if(!$socksfd){
    die "Connection to SOCKS failed";
}
my $smtp = Net::SMTP->new_from_fd($socksfd->fileno, 'r+' ) or die $!;

#HACK: there is "220 host.domain.net" line we must read otherwise Net::SMTP would not work!
$smtp->getline();

$smtp->hello("localhost") or die $smtp->message();
#from here Net::SMTP business as usual...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜