Amazon-SendToKindle

 view release on metacpan or  search on metacpan

lib/Amazon/SendToKindle.pm  view on Meta::CPAN

#!/usr/bin/perl -w

# SendToKindle.pm
#
# Send a file to Amazon's personal document service.

package Amazon::SendToKindle;

use strict;
use warnings;

require Exporter;
our @ISA = qw(Exporter);
our $VERSION = "0.2";
our %EXPORT_TAGS = ('all' => [qw(new send)]);
our @EXPORT_OK = (@{ $EXPORT_TAGS{'all'} });

use Net::SMTP::TLS;
use MIME::Lite;

# Constructor.
sub new {
	my ($class) = @_;
	my $self = {
		file_name => $_[1],
		address => $_[2],
		smtp_server => $_[3],
		smtp_port => $_[4],
		smtp_user => $_[5],
		smtp_password => $_[6]
	};

	bless $self, $class;
	return $self;
}

# Sends the document.
sub send {
	my ($self, $account, $convert) = @_;
	$account = "$account\@kindle.com";

	# Setup Net::SMTP.
	my $email = new Net::SMTP::TLS(
		$self->{smtp_server},
		Port => $self->{smtp_port},
		User => $self->{smtp_user},
		Password => $self->{smtp_password},
		Timeout => 60);
	$email->mail($self->{address});
	$email->to($account);
	$email->data();

	# Prepare the email subject.
	my $subject = "";
	if ($convert) {
		$subject = "convert";
	}

	# Setup MIME::Lite.
	my $msg = MIME::Lite->new(
        From    => $self->{address},
        To      => $account,
        Subject => $subject,
        Type    => "application/octet-stream",
        Path    => $self->{file_name});

	# Send email.
	$email->datasend($msg->as_string);
	$email->dataend();
	$email->quit();
}

1;
__END__

=head1 NAME

Amazon::SendToKindle - Send files to Amazon's personal document service.

=head1 SYNOPSIS

  use Amazon::SendToKindle;
  my $kindle = Whisper::SendToKindle->new(
      "document.pdf",
      "your@email.com",
      "smtp.server.com",
      $port,
      "username",
      "password);
  $kindle->send("amazon_username", 0);  # Do not include the @kindle.com

=head1 DESCRIPTION



( run in 1.816 second using v1.01-cache-2.11-cpan-39bf76dae61 )