Created
August 24, 2010 19:11
-
-
Save mschmitt/548125 to your computer and use it in GitHub Desktop.
My standard MIME::Lite application example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
use diagnostics; | |
use MIME::Lite; | |
use File::Basename; | |
my $sender = 'Alice <[email protected]>'; | |
my $recipient = 'Bob <[email protected]>'; | |
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