HTML mail formating in UNIX

Hi i need to send mail from my Unix server i used the below code.

From: TTS.OO.Monitoring.Operations
Subject: Error
X-Mailer: htmlmail 1.0
Mime-Version: 1.0
Content-Type: text/html; charset=US-ASCII
<HTML><head><style type='text/css'>
table.altrowstable { font-family: verdana,arial,sans-serif; font-size:13px; color:#333333 }
table.altrowstable th { border-width: 2px; border-style: solid; border-color: #a9c6c9; }
table.altrowstable td { border-width: 2px; border-style: solid; border-color: #a9c6c9; }
.oddrowcolor{ background-color:#d4e3e5;}
.evenrowcolor{ background-color:#c3dde0; }
</style></head><Body>
Hi All,
 
<BR></BR>
<TABLE class='altrowstable' id='alternatecolor'>
<TR bgcolor='#FFFF99' >
<TD>
TIMESTAMP     |        ORDERNO     |          SHIP_ADV_NO        |           REASON          | EMPTY FIELDS
*******************************************************************************************************************************
2012-04-24      |       10739022730     |       1027699274      |       PersonInfoShipTO details missing        |       FirstName,LastName,
-------------------------------------------------------------------------------------------------------------------------------
2012-04-24      |       10739022730     |       1027699275      |       PersonInfoShipTO details missing        |       FirstName,LastName,
-------------------------------------------------------------------------------------------------------------------------------
2012-04-24      |       10739022730     |       1027699276      |       PersonInfoShipTO details missing        |       FirstName,LastName,
</TD></TR>
</TABLE>
<BR></BR>
 
Thanks,
</body>    </html>
Online Ops-OMS Support

my output is

Hi All, 
 

 
TIMESTAMP | ORDERNO | SHIP_ADV_NO | REASON | EMPTY FIELDS ******************************************************************************************************************************* 2012-04-24 | 10739022730 | 1027699274 | PersonInfoShipTO details missing | FirstName,LastName, ------------------------------------------------------------------------------------------------------------------------------- 2012-04-24 | 10739022730 | 1027699275 | PersonInfoShipTO details missing | FirstName,LastName, ------------------------------------------------------------------------------------------------------------------------------- 2012-04-24 | 10739022730 | 1027699276 | PersonInfoShipTO details missing | FirstName,LastName, 
 
 
 
Thanks, 
Online Ops-OMS Support 

in the output i need some formatting.I am getting the extra ----------- in the mail i just need lines one below the one.

TIMESTAMP     |        ORDERNO     |          SHIP_ADV_NO        |           REASON          | EMPTY FIELDS     
*******************************************************************************************************************************
2012-04-24          |              10739022730      |              1027699274         |              PersonInfoShipTO details missing             |                FirstName,LastName,
-------------------------------------------------------------------------------------------------------------------------------
2012-04-24          |              10739022730      |              1027699275         |              PersonInfoShipTO details missing             |                FirstName,LastName,
-------------------------------------------------------------------------------------------------------------------------------
2012-04-24          |              10739022730      |              1027699276         |              PersonInfoShipTO details missing             |                FirstName,LastName,
 

I need formatted output.newline inside the Body tag is not identified it seems.Please hel[p me guys.
my OS version is
SunOS wapsx001 5.10 Generic_147147-26 sun4v sparc SUNW,Sun-Fire-T200

This is not clearly understandable.

where is the extra ----------- in your output.

if you include the table output in td it will consider it in one column..
I consider you are extracting data from Oracle DB? IF yes please read below article

Generating HTML Reports from SQL*Plus

---------- Post updated at 03:59 PM ---------- Previous update was at 03:52 PM ----------

to add....
save below in a file say mail_body
From: TTS.OO.Monitoring.Operations
Subject: Error
X-Mailer: htmlmail 1.0
Mime-Version: 1.0
Content-Type: text/html; charset=US-ASCII

loginto sqlplus -s user/password
SET MARKUP HTML ON SPOOL ON
spool mail_body append
run the query
exit

cat mail_body|sendmail <to address>

hi i am not getting the data from DB ,
i am creating text file in such a pattern (which is body of mail) to be sent as a mail.

try something like below.. alter this to add table structure color etc..

 
awk -F"|" 'BEGIN{print "<table border=\"1\">"} NR%2{print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}'  filename

here filename is the one which contains your table data

hi i dunno how to run the code,if i run in the command line i am getting the below output

nawk -F"|" 'BEGIN{print "<table border=\"1\">"}NR%2{print"<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"}END{print"</table>"}' mail.txt
<table border="1">
<tr>
<td>TIMESTAMP                ORDERNO           SHIP_ADV_NO            REASON                                    Fields missing</td>
</tr>
<tr>
<td>2012-04-24      </td>
<td>       10739022730     </td>
<td>       1027699274      </td>
<td> PersonInfoShipTO details missing        </td>
<td>       FirstName,LastName,</td>
</tr>
</table>

how to run the given code.I hope the code is very useful to me thank u :slight_smile:

---------- Post updated 07-04-13 at 07:53 AM ---------- Previous update was 07-03-13 at 07:56 AM ----------

Hi i run the code but i am getting only first two lines of output.

I am not getting entire file as a output.

What changes needs to be done.
Thank u guys.

Let me try to help you.

Step 1:
Use try it yourself editor
Write your html code and see whether you receive the desired output

Step 2:
Once you confirm that Output is fine, use sendmail or mutt to send the HTML content . I prefer sendmail and here is an example

( echo "From: Mohana@XXX.com"
echo "To: Lakshmi@YYY.com"
echo "MIME-Version: 1.0"
echo "Content-Type: text/html"
echo "Subject: This is a test mail"
echo ""
cat my_content.html) |/usr/sbin/sendmail -t

Coming to your problem, you have specified newline is not working. Please make a note that you are writing a html code and <br> is the tag for new line.

Hope this will help you.

1 Like