in reply to Sending e-mail with attachments.

I've included a shorter snippet from production code below. You can combine the object instantiation & text part of the email in new(). The attach param is an array ref of attachments. In my case, I have the data in memory from a dynamically generated PDF, but I believe you can also give a path to a file as well.

One option to attach() is Filename, which I recommend you use to set a sane name for the attachment, ie. "Your_documents.pdf". You'll need some code to set $mime_type. My code only attaches PDF files, so I just hardcoded it.

sub send_mime { my $class = shift; my %args = (from=>'', to=>'', subject=>'Default Subject', body=>'', attach=>[], # [{data=>\$content, name=>'foo'}] @_, ); # 1. create main body of email my $body = $args{body}; $body = ref($body) ? $$body : $body; my $msg = MIME::Lite->new(From=>$args{from}, To=>$args{to}, Subject=>$args{subject}, Type=>'TEXT', Data=>$body, ); # 2. attach file(s) foreach my $attach ( @{$args{attach}} ) { my $data = $attach->{data}; $msg->attach(Type=>$mime_type, Data=>$$data, Filename=>$attach->{name}, ); } # 3. deliver email $msg->send(); }