2019-04-02 18:10:48 +00:00
|
|
|
package Travelynx::Helper::Sendmail;
|
2020-11-27 21:12:56 +00:00
|
|
|
# Copyright (C) 2020 Daniel Friesel
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: MIT
|
2019-04-02 18:10:48 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use 5.020;
|
|
|
|
|
|
|
|
use Encode qw(encode);
|
|
|
|
use Email::Sender::Simple qw(try_to_sendmail);
|
2020-03-14 13:56:02 +00:00
|
|
|
use MIME::Entity;
|
2019-04-02 18:10:48 +00:00
|
|
|
|
|
|
|
sub new {
|
2019-04-13 15:09:10 +00:00
|
|
|
my ( $class, %opt ) = @_;
|
2019-04-02 18:10:48 +00:00
|
|
|
|
2019-04-13 15:09:10 +00:00
|
|
|
return bless( \%opt, $class );
|
2019-04-02 18:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub custom {
|
2019-04-13 10:17:19 +00:00
|
|
|
my ( $self, $to, $subject, $body ) = @_;
|
2019-04-02 18:10:48 +00:00
|
|
|
|
2020-03-14 13:56:02 +00:00
|
|
|
my $reg_mail = MIME::Entity->build(
|
|
|
|
To => $to,
|
2020-03-14 13:57:30 +00:00
|
|
|
From => $self->{config}{from},
|
2020-03-14 13:56:02 +00:00
|
|
|
Subject => encode( 'MIME-Header', $subject ),
|
|
|
|
Type => 'text/plain',
|
|
|
|
Charset => 'UTF-8',
|
|
|
|
Encoding => 'quoted-printable',
|
|
|
|
Data => encode( 'utf-8', $body ),
|
2019-04-02 18:10:48 +00:00
|
|
|
);
|
|
|
|
|
2019-04-13 16:56:06 +00:00
|
|
|
if ( $self->{config}->{disabled} ) {
|
2019-04-13 10:17:19 +00:00
|
|
|
|
2019-04-02 18:10:48 +00:00
|
|
|
# Do not send mail in dev mode
|
2019-04-17 11:07:05 +00:00
|
|
|
$self->{log}->info("sendmail to ${to}: ${subject}\n\n${body}");
|
2019-04-02 18:10:48 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return try_to_sendmail($reg_mail);
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|