draw html tables and send in mail

draw html tables and send in mail

am 01.06.2011 07:05:30 von Irfan Sayed

--0-1589504126-1306904730=:38416
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Hi All, =0AI wrote perl script to draw html tables and send that html=
tables in mail . i used two modules 1: html::tables and 2: mail::sendmail =
but when i send mail , it never prints the actual table in the mail b=
ody following is the code snippet, use HTML::Table;=0Ause Mail::S=
endmail; $table =3D new HTML::Table(2, 2);        =A0=
      =A0 print '

Start

';          =
       print $table->getTable;          =A0=
    =A0 print '

End

';=A0 =A0 %mail =3D ( To    =
=A0 =3D> 'abc@abc.com',             From  =A0 =
=3D> 'abc@abc.com',             Message =3D> "$tabl=
e",             'content-type' =3D> 'text/html; cha=
rset=3D"iso-8859-1"',          =A0 );     $mai=
l{body} =3D $table; =A0 $mail{smtp} =3D 'ustu-zone.relay.abc.com';=0A=
=A0 sendmail(%mail) or die $Mail::Sendmail::error;   print "OK. Log say=
s:\n", $Mail::Sendmail::log; plz suggest =0A
--0-1589504126-1306904730=:38416--

Re: draw html tables and send in mail

am 01.06.2011 10:06:17 von Shlomi Fish

Hi Irfan,

thanks for trying Perl. A few comments on your code.

On Wednesday 01 Jun 2011 08:05:30 Irfan Sayed wrote:
> Hi All,
>=20
>=20
> I wrote perl script to draw html tables and send that html tables in mail=
.
> i used two modules 1: html::tables and 2: mail::sendmail
>=20
> but when i send mail , it never prints the actual table in the mail body
>=20
> following is the code snippet,
>=20

Please properly capitalise your English text - as case is case-sensitive th=
ere=20
is no such module as "mail::sendmail".

> use HTML::Table;
> use Mail::Sendmail;
>=20

1. Add "use strict;" and "use warnings;" to the beginning:

http://perl-begin.org/tutorials/bad-elements/#no-strict-and- warnings

> $table =3D new HTML::Table(2, 2);
> print '

Start

';
> print $table->getTable;
> print '

End

';=20
>=20

1. Declare the variable using "my" to make "use strict;" happy.

[code]
my $table
[/code]

2. After that please avoid indirect-object notation:

http://perl-begin.org/tutorials/bad-elements/#indirect-objec t-notation

3. Your indentation is bad. the "prints" should be aligned to the strating=
=20
line - not in the middle.

4. You probably don't want to print this stuff to STODUT here. I don't know=
=20
what it does actually.

> %mail =3D ( To =3D> 'abc@abc.com',
> From =3D> 'abc@abc.com',
> Message =3D> "$table",
> 'content-type' =3D> 'text/html; charset=3D"iso-8859-1"',
> );

1. Declare %mail using "my".

2. 'content-type' is probably improperly captalised.

3. The single-qoutes handling in this are bad.

4. Please use UTF-8 instead of iso-8859-1. We are in 2011, not 1990.

> =20
> $mail{body} =3D $table;

You can put that inside the %mail.

>=20
> $mail{smtp} =3D 'ustu-zone.relay.abc.com';

Likewise.

> sendmail(%mail) or die $Mail::Sendmail::error;
> print "OK. Log says:\n", $Mail::Sendmail::log;
>=20
> plz suggest

=46rom where did you learn Perl? This is very bad code.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

Regards,

Shlomi Fish

=2D-=20
=2D--------------------------------------------------------- -------
Shlomi Fish http://www.shlomifish.org/
The Case for File Swapping - http://shlom.in/file-swap

Trying to block Internet pornography is like climbing a waterfall and trying
to stay dry. (-- one of Shlomi Fish's Internet Friends)

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: draw html tables and send in mail

am 01.06.2011 10:29:44 von John SJ Anderson

On Wed, Jun 1, 2011 at 01:05, Irfan Sayed wrote=
:

[ snip ]
> use HTML::Table;
> use Mail::Sendmail;
>
> $table =3D new HTML::Table(2, 2);
>              =
    print '

Start

';
>              =
    print $table->getTable;
>              =
    print '

End

';
>
>   %mail =3D ( To      =3D> 'abc@abc.com',
>              From=
    =3D> 'abc@abc.com',
>              Messag=
e =3D> "$table",
>              'conte=
nt-type' =3D> 'text/html; charset=3D"iso-8859-1"',
>            );
>
>   $mail{body} =3D $table;
>
>   $mail{smtp} =3D 'ustu-zone.relay.abc.com';
>   sendmail(%mail) or die $Mail::Sendmail::error;
>   print "OK. Log says:\n", $Mail::Sendmail::log;
>
> plz suggest
>

ObCodeReview: Turn on 'use strict' and 'use warnings', please.

First, you should probably read the Mail::Sendmail FAQ on HTML email:
That will explain
how to properly construct a multipart message that has both text and
HTML parts. (Note that you're going to need to figure out how to
represent your HTML table in text form.)

Second, when you do the assignment to the 'body' key of the message
hash, you're assigning the actual object. What you want to assign is
the textual version of the table -- so that line should look like:

$mail{body} =3D $table->getTable;

(This is somewhat confusing, as HTML::Table overrides stringification
-- so depending on the context you're evaluating it in, sometimes
$table is going to turn into a string and sometimes it's going to
remain an object unless you explicitly turn it into a string. That
assignment is an example of the latter case.)

j

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: draw html tables and send in mail

am 06.06.2011 10:30:35 von Chris Nehren

On Wed, Jun 01, 2011 at 04:29:44 -0400 , John SJ Anderson wrote:
> First, you should probably read the Mail::Sendmail FAQ on HTML email:
> That will explain
> how to properly construct a multipart message that has both text and
> HTML parts. (Note that you're going to need to figure out how to
> represent your HTML table in text form.)

There's Text::Table on CPAN that I've found to be extremely useful for
precisely this task. Can't recommend it highly enough.

--
Chris Nehren | Coder, Sysadmin, Masochist
Shadowcat Systems Ltd. | http://shadowcat.co.uk/

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/