Skip to content

Instantly share code, notes, and snippets.

@jnbek
Created March 23, 2012 18:55
Show Gist options
  • Save jnbek/2173790 to your computer and use it in GitHub Desktop.
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
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