| 1 | # Copyrights 1995-2024 by [Mark Overmeer <markov@cpan.org>]. | ||
| 2 | # For other contributors see ChangeLog. | ||
| 3 | # See the manual pages for details on the licensing terms. | ||
| 4 | # Pod stripped from pm file by OODoc 2.03. | ||
| 5 | # This code is part of the bundle MailTools. Meta-POD processed with | ||
| 6 | # OODoc into POD and HTML manual-pages. See README.md for Copyright. | ||
| 7 | # Licensed under the same terms as Perl itself. | ||
| 8 | |||
| 9 | # Based on smtp.pm, adapted by Maciej Żenczykowski | ||
| 10 | |||
| 11 | package Mail::Mailer::smtps;{ | ||
| 12 | our $VERSION = '2.22'; | ||
| 13 | } | ||
| 14 | |||
| 15 | use base 'Mail::Mailer::rfc822'; | ||
| 16 | |||
| 17 | use strict; | ||
| 18 | |||
| 19 | use Net::SMTP::SSL; | ||
| 20 | use Mail::Util qw(mailaddress); | ||
| 21 | use Carp; | ||
| 22 | |||
| 23 | sub can_cc { 0 } | ||
| 24 | |||
| 25 | sub exec { | ||
| 26 | my ($self, $exe, $args, $to) = @_; | ||
| 27 | my %opt = @$args; | ||
| 28 | my $host = $opt{Server} || undef; | ||
| 29 | $opt{Debug} ||= 0; | ||
| 30 | $opt{Port} ||= 465; | ||
| 31 | |||
| 32 | my $smtp = Net::SMTP::SSL->new($host, %opt) | ||
| 33 | or return undef; | ||
| 34 | |||
| 35 | if($opt{Auth}) | ||
| 36 | { $smtp->auth(@{$opt{Auth}}) | ||
| 37 | or return undef; | ||
| 38 | } | ||
| 39 | |||
| 40 | ${*$self}{sock} = $smtp; | ||
| 41 | |||
| 42 | $smtp->mail($opt{From} || mailaddress); | ||
| 43 | $smtp->to($_) for @$to; | ||
| 44 | $smtp->data; | ||
| 45 | |||
| 46 | untie *$self if tied *$self; | ||
| 47 | tie *$self, 'Mail::Mailer::smtps::pipe', $self; | ||
| 48 | $self; | ||
| 49 | } | ||
| 50 | |||
| 51 | sub set_headers($) | ||
| 52 | { my ($self, $hdrs) = @_; | ||
| 53 | $self->SUPER::set_headers | ||
| 54 | ( { From => "<" . mailaddress() . ">" | ||
| 55 | , %$hdrs | ||
| 56 | , 'X-Mailer' => "Mail::Mailer[v$Mail::Mailer::VERSION] " | ||
| 57 | . " Net::SMTP[v$Net::SMTP::VERSION]" | ||
| 58 | . " Net::SMTP::SSL[v$Net::SMTP::SSL::VERSION]" | ||
| 59 | } | ||
| 60 | ); | ||
| 61 | } | ||
| 62 | |||
| 63 | sub epilogue() | ||
| 64 | { my $self = shift; | ||
| 65 | my $sock = ${*$self}{sock}; | ||
| 66 | |||
| 67 | my $ok = $sock->dataend; | ||
| 68 | $sock->quit; | ||
| 69 | |||
| 70 | delete ${*$self}{sock}; | ||
| 71 | untie *$self; | ||
| 72 | $ok; | ||
| 73 | } | ||
| 74 | |||
| 75 | sub close(@) | ||
| 76 | { my ($self, @to) = @_; | ||
| 77 | my $sock = ${*$self}{sock}; | ||
| 78 | |||
| 79 | $sock && fileno $sock | ||
| 80 | or return 1; | ||
| 81 | |||
| 82 | my $ok = $self->epilogue; | ||
| 83 | |||
| 84 | # Epilogue should destroy the SMTP filehandle, | ||
| 85 | # but just to be on the safe side. | ||
| 86 | $sock && fileno $sock | ||
| 87 | or return $ok; | ||
| 88 | |||
| 89 | close $sock | ||
| 90 | or croak 'Cannot destroy socket filehandle'; | ||
| 91 | |||
| 92 | $ok; | ||
| 93 | } | ||
| 94 | |||
| 95 | package Mail::Mailer::smtps::pipe;{ | ||
| 96 | our $VERSION = '2.22'; | ||
| 97 | } | ||
| 98 | |||
| 99 | |||
| 100 | sub TIEHANDLE | ||
| 101 | { my ($class, $self) = @_; | ||
| 102 | my $sock = ${*$self}{sock}; | ||
| 103 | bless \$sock, $class; | ||
| 104 | } | ||
| 105 | |||
| 106 | sub PRINT | ||
| 107 | { my $self = shift; | ||
| 108 | my $sock = $$self; | ||
| 109 | $sock->datasend( @_ ); | ||
| 110 | } | ||
| 111 | |||
| 112 | 1; |