use LWP::UserAgent; use HTTP::Request::Common 'POST'; # I'm using encode_base64 from MIME::Base64, but you can use something # else if you prefer. use MIME::Base64 'encode_base64'; # I'm using the DateTime module to generate the "Date" header for my # e-mail, but you can use something else if you prefer. use DateTime; my @parts = ( { 'Content-Type' => 'text/plain', 'Content-Disposition' => 'inline', 'CONTENT' => 'Hello world', }, { 'Content-Type' => 'text/html', 'Content-Disposition' => 'attachment; filename=example.html', 'CONTENT' => 'HW

Hello world', }, { 'Content-Type' => 'text/plain', 'Content-Disposition' => 'attachment; filename="another example.txt"', 'CONTENT' => 'Hello world', }, ); my $boundary = join '-', map { sprintf '%08x', rand(2**32) } 0..3; my $body = "This is a multipart message in MIME format.\n\n"; foreach (@parts) { my %part = %$_; my $part_body = delete $part{CONTENT}; $body .= "--$boundary\n"; $body .= "$_: $part{$_}\n" for keys %part; $body .= "Content-Transfer-Encoding: base64\n"; $body .= "\n"; $body .= encode_base64($part_body)."\n"; } $body .= "--$boundary--\n"; my $req = POST( 'mailto:mail@tobyinkster.co.uk', From => 'tai@g5n.co.uk', Date => DateTime->now->strftime('%a, %d %b %Y %H:%M:%S %z'), Subject => 'Test Message', Content_Type => qq(multipart/mixed; boundary="$boundary"), Content => $body, ); my $response = LWP::UserAgent->new->request($req);