App-Zapzi
view release on metacpan or search on metacpan
lib/App/Zapzi/Distributors/Email.pm view on Meta::CPAN
package App::Zapzi::Distributors::Email;
# ABSTRACT: distribute a published eBook by sending an email
use utf8;
use strict;
use warnings;
our $VERSION = '0.017'; # VERSION
use App::Zapzi;
use Carp;
use Email::MIME 1.924;
use Email::Sender::Simple 1.300006 qw(sendmail);
use Email::Simple::Creator;
use Email::Simple;
use Path::Tiny;
use IO::All;
use Moo;
use Try::Tiny;
with 'App::Zapzi::Roles::Distributor';
sub name
{
return 'Email';
}
sub distribute
{
my $self = shift;
unless ($self->destination)
{
$self->_set_completion_message("Email recipient does not exist");
return 0;
}
my $email = $self->_create_message();
try
{
sendmail($email);
$self->_set_completion_message("Emailed to " . $self->destination);
return 1;
}
catch
{
my $message = (split /\n/, $_)[0] // "unknown error";
$self->_set_completion_message($message);
return;
};
}
sub _create_message
{
my $self = shift;
my $base = path($self->file)->basename;
my @parts =
(
Email::MIME->create(
attributes =>
{
content_type => "text/plain",
},
body => 'Zapzi published eBook attached.',
),
Email::MIME->create
(
attributes =>
{
filename => $base,
content_type => "application/octet-stream",
encoding => "base64",
disposition => "attachment",
Name => $base
},
( run in 2.828 seconds using v1.01-cache-2.11-cpan-98e64b0badf )