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

Hello!
We have an emaillist of about 8000 people and twice a month we send out an email to all of them.

All of our emails are 'html' and we like our users to receive them as a webpage in their inbox since most of them are using Microsoft Outlook.

What I usually do is take the list of emails, copy it into my buffer and then paste it into a MS outlook new email and then press send. I do this about 20 times and i'm sick and tired of doing it.

I want to use sendmail, but when I do the email comes into the users inbox as html instead of a webpage.

What do i need to put into the html (or in send mail) so that the email is a webpage and not html?

This way i can just write a script to systematically go through each email and send our group an email -- no more cutting and pasting!!!

  • Comment on sending an email using sendmail so that it looks like a webpage and not html

Replies are listed 'Best First'.
Re: sending an email using sendmail so that it looks like a webpage and not html
by monkey_boy (Priest) on Jul 07, 2004 at 12:13 UTC
    You need to set the mime type , use something like this:

    use Mail::Mailer; my $mailer = Mail::Mailer->new("sendmail"); $mailer->open({ From => '$you', To => $mailto, Subject => 'foo', 'Content-type'=> 'text/html' }) or warn "Can't open: $!\n"; print $mailer $mail_string; $mailer->close();
    I should really do something about this apathy ... but i just cant be bothered
Re: sending an email using sendmail so that it looks like a webpage and not html
by gellyfish (Monsignor) on Jul 07, 2004 at 12:21 UTC

    You may get away with adding a Content-Type: text/html header to the mail message but I would suggest that probably the easiest way of doing this is to use the module MIME::Lite - this can be as easy as:

    use MIME::Lite; + my $msg = MIME::Lite->new( From =>'jns@localhost', To =>'jonathan@localhost', Subject =>'Test', Type =>'text/html', Data =>'<h1>THis is a test</h1>'); $msg->send();
    Of course you would need to add the extra code to loop through the list.

    /J\

Re: sending an email using sendmail so that it looks like a webpage and not html
by edan (Curate) on Jul 07, 2004 at 12:14 UTC

    You'll need to set the "Content-Type" header to "text/html".

    Something like:

    Mail::Sendmail::sendmail( To => '...', # ... 'Content-Type' => 'text/html', );
    -->
    --
    edan

Re: sending an email using sendmail so that it looks like a webpage and not html
by cosmicsoup (Beadle) on Jul 07, 2004 at 12:56 UTC
    I use the following code to read in an html prepared file and send it in the appropriate format. My understanding is that you can not use the email_template and use a link instead.
    #!/usr/bin/perl use MIME::Lite::HTML; $today = `date -I`; chop($today); $email_template = "/data/staging/eod/andy/weekly_file.$today.html"; #HEADER $msg = MIME::Lite->new( From =>'Admin@mysite.com', To =>'person1@somesite.com, person2@somesite.com', Subject =>"Daily Status - $today", Type =>'multipart/related', ); #BODY open(TEMPLATE, $email_template); while (<TEMPLATE>){ $buffer .= $_; } close(TEMPLATE); $msg->attach(Type => 'text/html', Data=> $buffer); #SEND THE EMAIL $msg->send;
    I hope this helps.

    Louis
Re: sending an email using sendmail so that it looks like a webpage and not html
by ishnid (Monk) on Jul 07, 2004 at 14:38 UTC
    MIME::Lite can create multipart HTML emails (with images included). Might be worth a look.
Re: sending an email using sendmail so that it looks like a webpage and not html
by Ven'Tatsu (Deacon) on Jul 07, 2004 at 14:17 UTC
    If I read your question right your seeing the HTML source when you send through sendmail not the rendered HTML correct?

    The solution to this is not really perl related, you need to add a Content-Type: text/html; headder to your message.
Re: sending an email using sendmail so that it looks like a webpage and not html
by ercparker (Hermit) on Jul 07, 2004 at 16:27 UTC
    you can do what Ven'Tatsu suggested like this:
    open (MAIL, "|/path/to/sendmail -oi -t") || die "Couldn't open sendmai +l: $!\n"; print MAIL "From: user\@somedomain.com\n"; print MAIL "To: $recip\n"; print MAIL "Subject: whatever\n"; print MAIL "Content-type: text/html\n\n"; print MAIL qq*html content would go here*; close(MAIL);
    hope that helps
Re: sending an email using sendmail so that it looks like a webpage and not html
by zentara (Cardinal) on Jul 08, 2004 at 14:15 UTC
    You can send html-mail with inline photos, and you can put a link to your webpage in the mail, here is a sample. The trick is the cid tag. Hope it helps.
    #!/usr/bin/perl -w # Send HTML document with inline images use strict; use MIME::Lite; # Create a new MIME Lite object my $msg = MIME::Lite->new( From =>'foo@foo123.com', To =>'whoever@wherever.com', Subject =>'Hi', Type =>'multipart/related'); # Add the body to your HTML message $msg->attach(Type => 'text/html', Data => qq{ <BODY BGCOLOR=#FFFFFF> <H2>Hi</H2> <P ALIGN="left"> This is an HTML message. </P> <P ALIGN="left"> <A HREF="http://foo123.com/">Here's a link</A>. </P> <P ALIGN="middle"> <IMG SRC="cid:2uni2.jpg"> </P> </BODY> }); # Attach the image $msg->attach(Type => 'image/jpg', Id => '2uni2.jpg', Path => '2uni2.jpg'); # Send it $msg->send();

    I'm not really a human, but I play one on earth. flash japh
Re: sending an email using sendmail so that it looks like a webpage and not html
by neilwatson (Priest) on Jul 07, 2004 at 16:16 UTC
    I built this Cadillac of email programs for some marketing folks to use. They are not UNIX savvy so I added losts of logging and error checking.

    Neil Watson
    watson-wilson.ca