2019-04-02 18:10:48 +00:00
|
|
|
package Travelynx::Helper::Sendmail;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use 5.020;
|
|
|
|
|
|
|
|
use Encode qw(encode);
|
|
|
|
use Email::Sender::Simple qw(try_to_sendmail);
|
|
|
|
use Email::Simple;
|
|
|
|
|
|
|
|
sub new {
|
|
|
|
my ($class) = @_;
|
|
|
|
|
2019-04-13 10:17:19 +00:00
|
|
|
return bless( {}, $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
|
|
|
|
|
|
|
my $reg_mail = Email::Simple->create(
|
|
|
|
header => [
|
|
|
|
To => $to,
|
|
|
|
From => 'Travelynx <travelynx@finalrewind.org>',
|
|
|
|
Subject => $subject,
|
|
|
|
'Content-Type' => 'text/plain; charset=UTF-8',
|
|
|
|
],
|
|
|
|
body => encode( 'utf-8', $body ),
|
|
|
|
);
|
|
|
|
|
2019-04-13 10:17:19 +00:00
|
|
|
if ( $self->app->config->{db}->{database} =~ m{travelynx_dev} ) {
|
|
|
|
|
2019-04-02 18:10:48 +00:00
|
|
|
# Do not send mail in dev mode
|
|
|
|
say "sendmail to ${to}: ${subject}\n\n${body}";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return try_to_sendmail($reg_mail);
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|