There are several facets to your question. One is how to create an HTML table, and the other is how to generate and send an HTML formatted email. Below is some code that roughly accomplishes each of those tasks. Much could be done to improve the code further, but it should still enable you to get started.

use strict; use warnings; use MIME::QuotedPrint; use HTML::Table; use Mail::Sendmail; # Read lines open(FILE, 'log.txt') or die "Can't open File: File does not exist $!" +; my @file = <FILE>; chomp @file; @file = reverse(@file); close FILE; # Create Table my $table = new HTML::Table; $table->addRow(split /\s\s+/) for (@file[0..23]); $table->setColBGColor(3, 'Green'); $table->setColFormat(1, '<font color="red">', '</font>'); $table->setColFormat(5, '<font color="blue">', '</font>'); # Create HTML email with table content unshift @{$Mail::Sendmail::mailcfg{'smtp'}}, 'localhost'; my $plain = encode_qp "html log included"; my $html = encode_qp $table; my $boundary = "====" . time() . "===="; my $date = Mail::Sendmail::time_to_date(); my %mail = ( From => 'me@localhost', To => 'user@host.com', Subject => "Report - Transfer Summary - $date", 'content-type' => "multipart/alternative; boundary=\"$boundary\"", ); $mail{body} = <<END_OF_BODY; --$boundary Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable $plain --$boundary Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <html>$html</html> --$boundary-- END_OF_BODY # Send email and finish sendmail( %mail ) or die "Error: $Mail::Sendmail::error\n"; printf "\nMail Sent @ $date\n";
Update

Here is more succinct code that uses a couple different CPAN modules to accomplish the goal:

use strict; use warnings; use HTML::Table; use MIME::Lite; use File::ReadBackwards; my $table = new HTML::Table; my $log = File::ReadBackwards->new('log.txt') or die $!; $table->addRow(split(/\s\s+/, $log->readline)) for (1..24); $table->setColBGColor(3, 'Green'); $table->setColFormat(1, '<font color="red">', '</font>'); $table->setColFormat(5, '<font color="blue">', '</font>'); $log->close; my $msg = MIME::Lite->new( From =>'me@localhost', To =>'recipient@somewhere', Subject =>'Transfer Summary', Type =>'text/html', Encoding =>'base64', Data =>$table, ); $msg->send;

In reply to Re: Logfile to HTML and MIME EMail table by Loops
in thread Logfile to HTML and MIME EMail table by sidsinha

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.