Something went wrong. Try again.
Perl game server for TLE Community
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253package Lacuna::Mailer;
use Moose;use utf8;use LWP::UserAgent;use Data::Dumper;use MIME::Base64;use Log::Any qw($log);
no warnings qw(uninitialized);
has from => ( is => 'rw', lazy => 1, default => 'TLE Community <noreply@mail.tlecommunity.com>',);
has api_key => ( is => 'ro', lazy => 1, default => sub { require Lacuna; return Lacuna->config->get('mailgun/api_key'); },);
# Sends mail using mailgun and configured API key. Returns true if mailgun# accepted the message.sub send { my ($self, $to, $subject, $message) = @_;
return 0 unless ($self->api_key);
my %form = ( from => $self->from, to => $to, subject => $subject, text => $message, );
my $response = LWP::UserAgent->new->post( 'https://api.mailgun.net/v3/mail.tlecommunity.com/messages', Content => [%form], Authorization => 'Basic '.encode_base64('user:'.$self->api_key), );
if (!$response->is_success) { $log->error("Failed to send mail: ".Dumper($response)); } return $response->is_success ? 1 : 0;}
no Moose;__PACKAGE__->meta->make_immutable;