1# Copyrights 2001-2020 by [Mark Overmeer].
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.02.
5# This code is part of distribution Mail-Transport.  Meta-POD processed with
6# OODoc into POD and HTML manual-pages.  See README.md
7# Copyright Mark Overmeer.  Licensed under the same terms as Perl itself.
8
9package Mail::Transport::Sendmail;
10use vars '$VERSION';
11$VERSION = '3.005';
12
13use base 'Mail::Transport::Send';
14
15use strict;
16use warnings;
17
18use Carp;
19
20
21sub init($)
22{   my ($self, $args) = @_;
23
24    $args->{via} = 'sendmail';
25
26    $self->SUPER::init($args) or return;
27
28    $self->{MTS_program}
29      = $args->{proxy}
30     || $self->findBinary('sendmail')
31     || return;
32
33    $self->{MTS_opts} = $args->{sendmail_options} || [];
34    $self;
35}
36
37#------------------------------------------
38
39
40sub trySend($@)
41{   my ($self, $message, %args) = @_;
42
43    my $program = $self->{MTS_program};
44    if(open(MAILER, '|-')==0)
45    {   my $options = $args{sendmail_options} || [];
46        my @to = map {$_->address} $self->destinations($message, $args{to});
47
48        # {} to avoid warning about code after exec
49        {  exec $program, '-i', @{$self->{MTS_opts}}, @$options, @to; }
50
51        $self->log(NOTICE => "Errors when opening pipe to $program: $!");
52        exit 1;
53    }
54
55    $self->putContent($message, \*MAILER, undisclosed => 1);
56
57    unless(close MAILER)
58    {   $self->log(NOTICE => "Errors when closing sendmail mailer $program: $!");
59        $? ||= $!;
60        return 0;
61    }
62
63    1;
64}
65
66#------------------------------------------
67
681;
69