Sending emails with Perl through SSL
I'm trying to send an email with Perl through SSL. The best package I've come acro开发者_运维百科ss, based on examples, is Net::SMTP::SSL. This appears to be the standard. Unfortunately, the constructor always returns undef
for me:
my $smtp = Net::SMTP::SSL->new('smtp.server.com', Port => 25, Debug => 1);
I have verified, re-verified, and re-re-verified the server name and port number using a .NET application that does essentially the same thing. Everything works fine with the .NET app, so I don't see any reason why I should have problems connecting to the smtp server.
It would be extremely helpful if the module would provide some sort of debugging information, but $!
is coming up blank. Is there any explanation for why the $smtp
variable would be come up undefined? Or is there any way I can find some useful debugging information from the constructor call?
Edit: Yes, I know that port 25 is a weird port to use with SSL. I don't know why this port was chosen, but this is the port that's being used. Unfortunately I'm constrained by time and it's going to be easier for me to figure this out with another technology than try to debug the cpan module. Thanks everyone for helping.
Net::SMTP::SSL uses Net::SMTP to do its work. In looking at the source for Net::SMTP in its new
sub, undef
is returned for a number of error conditions. To start, you can either step through this function call in a debugger, or manually sprinkle print statements throughout its code to see how far it is getting before bailing.
Also, check that you have IO::Socket::SSL installed - this is used for the network operations. If you installed your modules using the cpan
client you should have it, but other package managers like rpm sometimes screw up the dependency chain.
I would also double- and triple-check that you have the right port: Net::SMTP::SSL's documentation says:
Due to the nature of Net::SMTP's
new
method, it is not overridden to make use of a default port for the SMTPS service. Perhaps future versions will be smart like that. Port 465 is usually what you want, and it's not a pain to specify that.
精彩评论