Using socks5 proxy with Net::SMTP

天大地大妈咪最大 提交于 2019-12-22 14:38:32

问题


I 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?


回答1:


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...


来源:https://stackoverflow.com/questions/3253360/using-socks5-proxy-with-netsmtp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!