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

i can't, for the life of me, get this done right. I dunno whats going wrong. Looking at the email source, it looks as i believe it shoud -- but when it hits the yahoo/hotmail accounts, i just get 'content type=text/html' - as the body of the whole damn thing. sometimes i'll see that, and if i look at the source, it exhibits object/embed tags as xobject or xembed, rendering them useless (i've got a flash movie hardcoded to a url in there) i tried using Mime:Lite, but i had too many configuration problems.. any help would be GREATLY appreciated
sub send_email_html { local($to, $from, $subject, $bodyHTML, $bodyTEXT) = @_; open (MAIL,"|$sendmailprog -t") || &return_error("500", "Sendm +ail error"); print MAIL "To: $to\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n"; print MAIL "MIME-Version: 1.0\n"; print MAIL "Content-Transfer-Encoding: quoted-printable\n"; print MAIL "Content-type: multipart/alternative; "; print MAIL " boundary = unique-boundary-1\n"; print MAIL "This is a MIME encoded message.\n"; print MAIL "\n"; print MAIL "--unique-boundary-1\n"; print MAIL "Content-type: text/plain; charset=US-ASCII\n"; print MAIL "\n"; print MAIL "$bodyTEXT\n"; print MAIL "\n"; print MAIL "--unique-boundary-1\n"; print MAIL "Content-type: text/html; charset=US-ASCII\n"; print MAIL "\n"; print MAIL "$bodyHTML\n"; close (MAIL); }
or
use Mail::Bulkmail; $bulk = Mail::Bulkmail->new( Smtp => '127.0.0.1', From => 'from@myhost.com', Subject => 'attempt using mail bulkmail', Message => $body{html}, HTML => 1, ); $bulk->mail($toAddy);

Replies are listed 'Best First'.
Re: Sending Rich/HTML email
by tachyon (Chancellor) on May 08, 2002 at 07:36 UTC

    You should use either Mime::Lite or MIME::Entity as they were designed to take the heartache out of doing this. Anyway your problem is you hand rolled formatting is wrong. Amongst other things you need:

    boundary="some_string" --some_string what's this eh, we need two leading -- for the boundary --some_string blah, note extra two -- on end of closing boundary below --some_string--

    You have random spaces, no quotes (optional but good), missing leading and trailing -- and no closing boundary so your boudaries are broken. Here is an example generated using MIME::Entity that shows you the correct format. It also shows you how easy it is to use. You can attach text, html, binary files (images etc):

    use MIME::Entity; my $html = "<html>\n<head>\n</head>\n<body>\n <p>This is some text\n< +/body>\n</html>\n"; my $text = "This is some text\n"; ### Create the top-level, and set up the mail headers: $top = MIME::Entity->build(Type => "multipart/alternative", From => 'me@myhost.com', To => 'you@yourhost.com', Subject => "Hello World!"); $top->attach(Data => $text, Type => "text/plain", Encoding => "quoted-printable"); $top->attach(Data => $html, Type => "text/html", Encoding => "quoted-printable"); $top->print(\*STDOUT); __DATA__ Content-Type: multipart/alternative; boundary="----------=_1020843667-205993-0" Content-Transfer-Encoding: binary MIME-Version: 1.0 X-Mailer: MIME-tools 5.316 (Entity 5.212) From: me@myhost.com To: you@yourhost.com Subject: Hello World! This is a multi-part message in MIME format... ------------=_1020843667-205993-0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: quoted-printable This is some text ------------=_1020843667-205993-0 Content-Type: text/html Content-Disposition: inline Content-Transfer-Encoding: quoted-printable <html> <head> </head> <body> <p>This is some text </body> </html> ------------=_1020843667-205993-0--

    As an additional comment print MAIL "blah"; print MAIL "blech"...on and on could be replaced with a nice neat heredoc like this:

    $message = <<"END_MESSAGE"; To: $email Reply-to: <$our_email> From: $us <$our_email> Subject: $list_name Hello $name, $message $us END_MESSAGE open ('MAIL', "|$mail_prog -t -i") or DieNice("Can't open '$mail_prog' +: $!\n"); print MAIL $message;

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Sending Rich/HTML email
by nmerriweather (Friar) on May 08, 2002 at 17:12 UTC
    well i figured it out, so ill leave these tips for anyone who tries to do this in the future:

    1 - Content-Type NOT Content-type -- the T/t will muck up a lot of readers

    2 - Hotmail, yahoo and a bunch of other places strip out object/embed tags

    3 - view 'invisibles' little gremlins can pop up in code when you shift between a mac and *nix box

    4 - never use any words with all caps in an email subject -- it'll trigger a 'spam detector' 5 - the closing boundary has a -- at the end word, homies