我想将 Net::SMTP 与动态 socks 代理一起使用。 IO::Socket::Socks 可以识别 socks ,但是它应该如何与 net::smtp 一起使用?
最佳答案
我明白了,但它包含一些 hack,可能会或可能不会与 Net::SMTP 的 future 版本一起工作:
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...
关于perl - 将socks5代理与Net::SMTP一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3253360/