1 package SL::Mailer::SMTP;
5 use parent qw(Rose::Object);
7 use Rose::Object::MakeMethods::Generic
9 scalar => [ qw(myconfig mailer form) ]
15 Rose::Object::init(@_);
17 my $cfg = $::lx_office_conf{mail_delivery} || {};
18 $self->{security} = lc($cfg->{security} || 'none');
20 if ($self->{security} eq 'tls') {
21 require Net::SMTP::TLS;
24 $params{User} = $cfg->{user};
25 $params{Password} = $cfg->{password};
27 $self->{smtp} = Net::SMTP::TLS->new($cfg->{host} || 'localhost', Port => $cfg->{port} || 25, %params);
30 my $module = $self->{security} eq 'ssl' ? 'Net::SMTP::SSL' : 'Net::SMTP';
31 my $default_port = $self->{security} eq 'ssl' ? 465 : 25;
32 eval "require $module" or die $@;
34 $self->{smtp} = $module->new($cfg->{host} || 'localhost', Port => $cfg->{port} || $default_port);
35 $self->{smtp}->auth($cfg->{user}, $cfg->{password}) if $cfg->{login};
38 die unless $self->{smtp};
42 my ($self, %params) = @_;
44 $self->{smtp}->mail($params{from});
45 $self->{smtp}->recipient(@{ $params{to} });
52 # SMTP requires at most 1000 characters per line. Each line must be
53 # terminated with <CRLF>, meaning \r\n in Perl.
55 # First, normalize the string by removing all \r in order to fix
56 # possible wrong combinations like \n\r.
57 my $str = join '', @_;
60 # Now remove the very last newline so that we don't create a
61 # superfluous empty line at the very end.
64 # Split the string on newlines keeping trailing empty parts. This is
65 # requires so that input like "Content-Disposition: ..... \n\n" is
66 # treated correctly. That's also why we had to remove the very last
67 # \n in the prior step.
68 my @lines = split /\n/, $str, -1;
70 # Send each line terminating it with \r\n.
71 $self->{smtp}->datasend("$_\r\n") for @lines;
77 $self->{smtp}->dataend;
82 sub keep_from_header {
83 my ($self, $item) = @_;
84 return lc($item) eq 'bcc';