E-Mails auch per SMTP verschicken können
[kivitendo-erp.git] / SL / Mailer / Sendmail.pm
1 package SL::Mailer::Sendmail;
2
3 use strict;
4
5 use IO::File;
6 use SL::Template;
7
8 use parent qw(Rose::Object);
9
10 use Rose::Object::MakeMethods::Generic
11 (
12   scalar => [ qw(myconfig mailer form) ]
13 );
14
15 sub init {
16   my ($self) = @_;
17
18   Rose::Object::init(@_);
19
20   my $email         =  $self->mailer->recode($self->myconfig->{email});
21   $email            =~ s/[^\w\.\-\+=@]//ig;
22
23   my %temp_form     = ( %{ $self->form }, myconfig_email => $email );
24   my $template      = SL::Template::create(type => 'ShellCommand', form => \%temp_form);
25   my $sendmail      = $::lx_office_conf{applications}->{sendmail} || $::lx_office_conf{mail_delivery}->{sendmail} || "sendmail -t";
26   $sendmail         = $template->parse_block($sendmail);
27
28   $self->{sendmail} = IO::File->new("|$sendmail") || die "sendmail($sendmail): $!";
29 }
30
31 sub start_mail {
32 }
33
34 sub print {
35   my $self = shift;
36
37   $self->{sendmail}->print(@_);
38 }
39
40 sub send {
41   my ($self) = @_;
42   $self->{sendmail}->close;
43   delete $self->{sendmail};
44 }
45
46 sub keep_from_header {
47   0;
48 }
49
50 1;