Created
March 23, 2012 18:55
-
-
Save jnbek/2173790 to your computer and use it in GitHub Desktop.
all purpose Net::SMTP object constuct, trying SSL first before falling back on non-SSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $smtp_connection = $self->{'smtp_obj'} ||= do { | |
my $smtps_obj = eval { | |
require Net::SMTP::SSL; | |
my $s = Net::SMTP::SSL->new( | |
$args->{'smtp_server'}, | |
Port => 465, | |
Hello => $mail_domain, | |
Timeout => 10, | |
Debug => 0, | |
); | |
}; | |
if ($@ || !defined $smtps_obj) { | |
require Net::SMTP; | |
my $smtp_obj = Net::SMTP->new( | |
$args->{'smtp_server'}, | |
Hello => $mail_domain, | |
Timeout => 10, | |
Debug => 0, | |
); | |
$smtp_obj; | |
} | |
else { | |
$smtps_obj; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment