ultranerds has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

This is driving me nuts. I must be missing something stupid. I have the following sub:

sub send_email { use MIME::Lite; use MIME::Base64; use Encode; my $to = 'support@foobar.co.uk'; #$rec{'Email'}; my $from = $admin_email; my $subject = "webform $html_title"; my $html = "some test <b>message</b> foo bar test"; my $text = "some test message some plain version"; # $html = decode( 'utf-8', $html ); # $text = decode( 'utf-8', $text ); my ($status,$attach,$newfile); use Email::MIME; use Email::Address::XS; use Email::Sender::Simple qw(sendmail); use IO::All; use GT::MIMETypes; # multipart message my @alternative_parts = ( Email::MIME->create( body_str => $text, attributes => { encoding => 'quoted-printable', content_type => "text/plain", disposition => "inline", charset => "UTF-8", } ), Email::MIME->create( body_str => $html, attributes => { encoding => 'quoted-printable', charset => "UTF-8", content_type => "text/html", disposition => "inline", } ) ); my @attachment_parts; my $attach = "/path/to/file/tables.cgi"; if ($attach) { my $filename = (reverse split /\//, $attach)[0]; # also change +d in body => below my $content; my $mime = GT::MIMETypes::guess_type($filename); push @parts, Email::MIME->create( attributes => { filename => $filename, content_type => $mime, encoding => "base64", name => $filename, attachment => "attachment" }, body => io( $attach )->binary->all, ) } my $email = Email::MIME->create( header_str => [ From => $from, To => [ $to ], Subject => $subject ], parts => \@parts, attributes => { encoding => 'base64', charset => "UTF-8", content_type => "multipart/multipart", #disposition => "inline", } ); sendmail($email->as_string); print "EMAIL: " . $email->as_string. "\n\n"; # print for andy }

What it needs to do is include both a plain text and html body of the email. Then, also attached is a file (a .cgi just for testing :)).

While the emails comes through fine on Gmail - it buggers up on Outlook/Thunderbird. I have a feeling its the way I'm breaking up the "parts". From my understanding you need a "main" body part, which can be split into a plain text and html version - and then the attachment as another part of the main "part". I'm not too sure how to achieve this though?

This is how the "debug_structure" comes out:

Structure: + multipart/multipart; boundary="15846317930.c94ff7.26547" + text/plain; charset="UTF-8" + text/html; charset="UTF-8" + text/plain; attachment="attachment"; name="tables.cgi"

Thanks!

Andy