summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Helper
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-04-02 20:10:48 +0200
committerDaniel Friesel <derf@finalrewind.org>2019-04-02 20:10:48 +0200
commit4787dbae15118edcf17f503b6de37ce645d19cc3 (patch)
tree4ede51a588a04bd960d3ed4fdc9c3eb320dfb0ff /lib/Travelynx/Helper
parent68718860e29f5ce1c2c10afc99c0bfeb9943d6d6 (diff)
move mailing to sendmail helper
Diffstat (limited to 'lib/Travelynx/Helper')
-rw-r--r--lib/Travelynx/Helper/Sendmail.pm40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/Travelynx/Helper/Sendmail.pm b/lib/Travelynx/Helper/Sendmail.pm
new file mode 100644
index 0000000..c110a29
--- /dev/null
+++ b/lib/Travelynx/Helper/Sendmail.pm
@@ -0,0 +1,40 @@
+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) = @_;
+
+ return bless({}, $class);
+}
+
+sub custom {
+ my ($self, $to, $subject, $body) = @_;
+
+ 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 ),
+ );
+
+ if ($ENV{TRAVELYNX_DB_NAME} eq 'travelynx_deva') {
+ # Do not send mail in dev mode
+ say "sendmail to ${to}: ${subject}\n\n${body}";
+ return 1;
+ }
+
+ return try_to_sendmail($reg_mail);
+}
+
+1;