2

我想将 Net::SMTP 与动态 socks 代理一起使用。IO::Socket::Socks 知道 socks 但它应该如何与 net::smtp 一起使用?

4

1 回答 1

3

我想通了,但它包括可能会或可能不会与 Net::SMTP 的未来版本一起使用的hack:

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...
于 2011-03-11T18:37:03.007 回答