#!/usr/bin/perl
use lib "lib";
use MIME::Lite;


$msg = new MIME::Lite 
     To       => 'eryq',
     Subject  => 'SMTP test',
     Type     => 'image/gif',		       
     Encoding => 'base64',
     Path     => "./docs/MIME/mime-sm.gif";

# sendmail...
$msg->replace('Subject', "smtptest: 1: sendmail via send");
$msg->send;
print "sent 1\n";

# sendmail...
$msg->replace('Subject', "smtptest: 2: sendmail explicit");
$msg->send_by_sendmail('/usr/lib/sendmail -t -oi -oem');
print "sent 2\n";

# SMTP...
$msg->replace('Subject', "smtptest: 3: smtp explicit");
$msg->send_by_smtp('localhost');
print "sent 3\n";

# SMTP...
MIME::Lite->send('smtp', 'localhost');
$msg->replace('Subject', "smtptest: 4: smtp via send");
$msg->send;
print "sent 4\n";

# Sub:
$msg->replace('Subject', "smtptest: 5: sub explicit");
$msg->send_by_sub(\&mysendmail, "/usr/lib/sendmail -t -oi -oem");
print "sent 5\n";

# Sub:
MIME::Lite->send('sub', \&mysendmail,  "/usr/lib/sendmail -t -oi -oem");
$msg->replace('Subject', "smtptest: 6: sub via send");
$msg->send;
print "sent 6\n";


sub mysendmail {
    my ($self, $sendmailcmd) = @_;

    # Do it:
    my $pid;
    open SENDMAIL, "|$sendmailcmd" or die "open |$sendmailcmd: $!";
    $self->print(\*SENDMAIL);
    close SENDMAIL;
    return (($? >> 8) ? undef : 1);
}

