尝试使用Email::Sender::Transport::SMTPS发送电子邮件。我的交通工具是:
my $transport = Email::Sender::Transport::SMTPS->new({
host => $smtpserver,
ssl => 'starttls',
sasl_username => $smtpuser,
sasl_password => $smtppassword,
debug => 1,
});
尝试发送电子邮件时,调试说:
Net::SMTPS=GLOB(0x7f893b2b00f0)<<< 250-SIZE 52428800
Net::SMTPS=GLOB(0x7f893b2b00f0)<<< 250-8BITMIME
Net::SMTPS=GLOB(0x7f893b2b00f0)<<< 250-PIPELINING
Net::SMTPS=GLOB(0x7f893b2b00f0)<<< 250-STARTTLS
Net::SMTPS=GLOB(0x7f893b2b00f0)<<< 250 HELP
Net::SMTPS=GLOB(0x7f893b2b00f0)>>> STARTTLS
Net::SMTPS=GLOB(0x7f893b2b00f0)<<< 220 TLS go ahead
DEBUG: .../IO/Socket/SSL.pm:735: local error: SSL connect attempt failed error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
DEBUG: .../IO/Socket/SSL.pm:738: fatal SSL error: SSL connect attempt failed error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
unable to establish SMTP connection
可能是因为服务器使用self-signed
证书。 (在Thunderbird中使用相同的设置时,需要添加“信任此证书”设置。)
问题是:如何为Email::Sender::Transport::SMTPS
添加“信任此证书” - 从而允许发送电子邮件。
答案 0 :(得分:1)
没有直接的方法来提供Email :: Sender :: Transport :: SMTPS SSL特定参数。但是,由于最终使用IO:Socket::SSL,您可以通过这种限制来解决问题。从手册页:
这是使用IO :: Socket :: SSL看到的典型错误列表: ....
让用户无法使用SSL设置,以及错误的内置设置。
某些模块使用IO :: Socket :: SSL,但不向用户提供SSL设置。这通常与错误的内置设置或默认设置(例如关闭切换验证)相结合。因此,用户需要使用set_args_filter_hack或类似方法来解决这些限制。
因此你可以做的是
IO::Socket::SSL::set_args_filter_hack( sub {
my ($is_server,$args) = @_;
$args->{SSL_fingerprint} = 'sha1$437104....'
});
使用此选项,只要指纹与指定的指纹匹配,您就可以使证书锁定信任证书。您可以通过以下方式获取指纹:
openssl s_client -connect mail.example.org:25 -starttls smtp |\
openssl x509 -fingerprint -noout
替代方法是将证书用作SSL_ca_file
选项的受信任者。您也可以将SSL_verify_mode
设置为0(SSL_VERFY_NONE
),但由于这会禁用任何类型的验证,因此您只能将其用于测试。
请注意set_args_filter_hack
是全局的,它会影响程序中的所有IO :: Socket :: SSL对象。因此,根据程序,您应该在与Email :: Sender :: Transport :: SMTPS建立连接之前直接设置它,然后立即重置它。
有关这些选项的详细信息,请参阅documentation of IO::Socket::SSL。
答案 1 :(得分:0)
您可以使用new()构造函数方法
的选项来控制SSL使用情况-------------------Configuration: Employee - Win32 Debug--------------------
Compiling...
Employee.cpp
C:\Users\afaq\Desktop\del\Employee.cpp(42) : warning C4183: 'intgetMSalary': member function definition looks like a ctor, but name does not match enclosing class
C:\Users\afaq\Desktop\del\Employee.cpp(46) : warning C4183: 'intySalary': member function definition looks like a ctor, but name does not match enclosing class
C:\Users\afaq\Desktop\del\Employee.cpp(50) : warning C4183: 'intraise': member function definition looks like a ctor, but name does not match enclosing class
C:\Users\afaq\Desktop\del\Employee.cpp(41) : error C2065: 'returnmSalary' : undeclared identifier
C:\Users\afaq\Desktop\del\Employee.cpp(45) : error C2065: 'return12' : undeclared identifier
C:\Users\afaq\Desktop\del\Employee.cpp(45) : warning C4552: '*' : operator has no effect; expected operator with side-effect
C:\Users\afaq\Desktop\del\Employee.cpp(49) : error C2065: 'ySalary' : undeclared identifier
C:\Users\afaq\Desktop\del\Employee.cpp(63) : error C2065: 'Employeeem1' : undeclared identifier
C:\Users\afaq\Desktop\del\Employee.cpp(64) : error C2065: 'Employeeem2' : undeclared identifier
C:\Users\afaq\Desktop\del\Employee.cpp(66) : error C2065: 'em1' : undeclared identifier
C:\Users\afaq\Desktop\del\Employee.cpp(66) : error C2228: left of '.ySalary' must have class/struct/union type
C:\Users\afaq\Desktop\del\Employee.cpp(67) : error C2065: 'em2' : undeclared identifier
C:\Users\afaq\Desktop\del\Employee.cpp(67) : error C2228: left of '.ySalary' must have class/struct/union type
C:\Users\afaq\Desktop\del\Employee.cpp(69) : error C2228: left of '.raise' must have class/struct/union type
C:\Users\afaq\Desktop\del\Employee.cpp(71) : error C2228: left of '.raise' must have class/struct/union type
C:\Users\afaq\Desktop\del\Employee.cpp(72) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.
Employee.exe - 11 error(s), 5 warning(s)
在电子邮件/发件人/传输/ SMTPS.pm
"SSL_verify_mode"=>'SSL_VERIFY_NONE'
编辑:这真的很糟糕,因为根据评论你相信一切。相反,如果在linux / * nix上
# compatible
my $ssl = $self->ssl;
$ssl = 'ssl' if $self->ssl and $self->ssl ne 'starttls';
return (
$self->host,
Port => $self->port,
Timeout => $self->timeout,
defined $ssl ? (doSSL => $ssl) : (),
defined $self->helo ? (Hello => $self->helo) : (),
defined $self->localaddr ? (LocalAddr => $self->localaddr) : (),
defined $self->localport ? (LocalPort => $self->localport) : (),
defined $self->debug ? (Debug => $self->debug) : (),
"SSL_verify_mode"=>'SSL_VERIFY_NONE',#ADDED LINE
);