
Mailing an Excel spreadsheet via Perl
May 17th, 2007I thought I would pass on this little tidbit since it took me awhile to find out the specifics. Using the MIME::Lite module, it’s actually pretty easy. The only problem I had was figuring out the correct MIME type to use for the attachment.
my $SUBJECT = q(Example Spreadsheet Email!);
my $MESSAGE = q(This is the main message text body.);
my $XLSPATH = q(/home/foo/spreadsheets);
my $XLS = q(Example-20070517.xls);
my $msg = MIME::Lite->new(
From => $FROM,
To => $TO,
Cc => $CC,
Subject => $SUBJECT,
Type => q(multipart/mixed)
);
$msg->attach(
Type => q(TEXT),
Data => $MESSAGE
);
if($XLS) {
$msg->attach(
Type => q(application/msexcel),
Path => qq($XLSPATH/$XLS),
Filename => $XLS,
Encoding => q(base64)
);
}
$msg->send;
See, pretty painless =)