Skip to content

Instantly share code, notes, and snippets.

@mschmitt
Created August 24, 2010 19:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mschmitt/548125 to your computer and use it in GitHub Desktop.
Save mschmitt/548125 to your computer and use it in GitHub Desktop.
My standard MIME::Lite application example
#!/usr/bin/perl -w
use strict;
use diagnostics;
use MIME::Lite;
use File::Basename;
my $sender = 'Alice <alice@thisdomain.invalid>';
my $recipient = 'Bob <bob@otherdomain.invalid>';
my $file = "/home/alice/info.pdf";
my $smtphost = "127.0.0.1 25";
my $subject = "Demo Attachment";
my $coverletter = <<EOF;
Dear sirs,
plz find the desired information attached.
EOF
MIME::Lite->send('smtp', $smtphost, Timeout=>5);
my $msg = MIME::Lite->new(
From => $sender,
To => $recipient,
Subject => $subject,
Type => 'multipart/mixed'
);
$msg->attach(
Type => 'TEXT',
Data => $coverletter
);
$msg->attach(
Type => 'AUTO',
Path => $file,
Filename => basename($file),
Disposition => 'attachment'
);
$msg->send();
# To send through the local MTA for enqueueing the mail, e.g. sendmal or qmail-inject:
# MIME::Lite->send('sendmail', "/usr/lib/sendmail -t -oi "); # (Postfix)
# MIME::Lite->send('sendmail', "/var/qmail/bin/qmail-inject -f $absender $emfpaenger"); # (Qmail)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment