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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Sending HTML-formatted email
by davorg (Chancellor) on Nov 21, 2006 at 12:10 UTC

    (Can you please tidy up the formatting of this node. See Writeup Formatting Tips for more details.)

    You should look at the work of the Perl Email Project. Some of their tools will no doubt be of help to you.

    Oh, and if you insist on sending HTML email (email is a text medium dammit!) then at least also attach a plain text version of the message.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      Oh, and if you insist on sending HTML email (email is a text medium dammit!) then at least also attach a plain text version of the message.
      Old fart nitpicking aside: plenty of spam filters will block HTML only mails.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Sending HTML-formatted email
by calin (Deacon) on Nov 21, 2006 at 12:49 UTC

    Most modern mail clients identify links in plain text messages. I suggest you to start with a simple solution - you don't need Perl for that. Make an alias for your list of students in your .mailrc, create the body of the message with a plain text editor say in /home/rio/students-reminder, and then put a mail invocation in your crontab.

    If this isn't satisfactory, CPAN is your friend. I suggest take a look at Email::MIME::CreateHTML. There is a simple example right in the documentation.

Re: Sending HTML-formatted email
by zentara (Cardinal) on Nov 21, 2006 at 13:17 UTC
    Typing "html mail" into the Search box yields some good links, such as How to format email so Outlook renders HTML

    You may want to use a template

    #!/usr/bin/perl use strict; use warnings; use MIME::Lite; use HTML::Template; #by jeffa of perlmonks my $t = HTML::Template->new( filehandle => \*DATA ); $t->param( field => 'foo', data => 'bar', ); my $msg = MIME::Lite->new( From => 'me@myhost.com', To => 'you@yourhost.com', Subject => 'Hello HTML', Data => $t->output, # you can just use $myInfo here i +nstead Type => 'text/html', ); $msg->send; __DATA__ <html> <body> <h1>Hello HTML!</h1> <table> <tr> <td><tmpl_var field></td> <td><tmpl_var data></td> </tr> </table> </body> </html>

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Sending HTML-formatted email
by madbombX (Hermit) on Nov 21, 2006 at 12:40 UTC
    Check out Mail::Sender for sending the email HTML and plain text. You can send it multipart so it doesn't get blocked by a SPAM filter.
    use Mail::Sender; my $text_msg = "foo"; my $html_msg = "<p>foo</p>"; my $sender = new Mail::Sender { smtp => '127.0.0.1', from => "Teacher <me\@mydomain.com>", } $sender->OpenMultipart( { to => "$rcpt", subject => "$subject", multipart => "mixed", }) or die "Can't Open message: $sender->{'error_msg'}\n"; $sender->Part( { ctype => 'multipart/alternative' }); $sender->Part( { ctype => 'text/plain', disposition => 'NONE', msg => "$text_msg\n" }); $sender->Part( { ctype => 'text/html', disposition => 'NONE', msg => "$html_msg\n" }); $sender->Close() or die "Failed to send message: $sender->{'error_msg'}\n";
      from => "Teacher <me\@mydomain.com>",

      If you didn't use double quotes there, then you wouldn't need to escape the '@' character.

      from => 'Teacher <me@mydomain.com>',

      And that's one less potentially confusing piece of punctuation for your maintenance programmer[1] to deal with.

      [1] Yes. That might be you :-)

      --
      <http://dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

Re: Sending HTML-formatted email
by neilwatson (Priest) on Nov 21, 2006 at 14:42 UTC
    Did you bother to actually search past nodes before posting this question? It is certainly common (hint: check the code section).

    Neil Watson
    watson-wilson.ca

Re: Sending HTML-formatted email
by rio (Initiate) on Nov 21, 2006 at 12:39 UTC
    In that case, let me forget about HTML format. Can you help if it was plain text please?

    Cheers

      My advice remains the same:

      You should look at the work of the Perl Email Project. Some of their tools will no doubt be of help to you.

      You'll see lots of people recommending various modules from the Mail:: and MIME:: namespaces. My advice is to ignore that and to go straight for the Email:: modules. The Perl Email Project are building a simple, consistant and complete set of modules for dealing with email. I'm sure you will will find their tools easier to use than the older modules.

      --
      <http://dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg