For dealing with attachments use one of the perl
MIME
modules. I find that
MIME::Lite has been
strong-enough to do anything I've ever needed with
attachments/multipart messages. Here's an example of its usage
taken from the MIME::Lite documentation:
use MIME::Lite;
# Create a new multipart message:
$msg = new MIME::Lite
From =>'me@myhost.com',
To =>'you@yourhost.com',
Cc =>'some@other.com, some@more.com',
Subject =>'A message with 2 parts...',
Type =>'multipart/mixed';
# Add parts (each "attach" has same arguments as "new"):
attach $msg
Type =>'TEXT',
Data =>"Here's the GIF file you wanted";
attach $msg
Type =>'image/gif',
Path =>'aaa000123.gif',
Filename =>'logo.gif';
Once you have your message constructed with attachments then you
need to send it. I prefer to use
Net::SMTP to send
messages, but there are several other perl modules that
can send mail (and several ways of just doing it by hand).
If you're already using
MIME::Lite the easiest
method is to use its built-in
send function:
$msg->send;
If you're interested in delving deeper, O'Reilly has a
decent book entitled
Programming Internet Email
that covers most of the interesting internet e-mail
protocols and formats. It has a good
chapter on e-mail related Perl modules.