#!/usr/local/bin/perl -w
###########################################
# mail-to-kindle -- Mail an ebook to Kindle
# Mike Schilli, 2012 (m@perlmeister.com)
###########################################
use strict;
use MIME::Lite;

my( $file ) = @ARGV;

if( !defined $file ) {
    die "usage: $0 file.mobi";
}

my $msg = MIME::Lite->new(
    From    => 'm@perlmeister.com',
    To      => 
      'Gaxy Galaxy xxx@Kindle.com>',
    Subject => 'My Ebook',
    Type    => 'multipart/mixed'
);

my $part = MIME::Lite->new(
    Type     => 'text/plain',
    Data     => "some text\n",
);

$msg->attach( $part );

$msg->attach(
    Type        => 'application/mobi',
    Path        => $file,
    Filename    => $file,
    Disposition => 'attachment',
);

$msg->send( 'smtp', 'mail.some-smtp.com' );
