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(); }