Solved

What is the best way to extract and process information from an HTML email?

Posted on 2006-06-18
2
607 Views
Last Modified: 2010-04-04
I get notices from a courier company in HTML format, and in that email are one or more table rows that contain information about a failed delivery.  I would like to pick out that information and use it to automatically send my own email to the person whose delivery has failed giving them the same information but pulling their details from my own database.

Can anyone suggest the best way of going about this?

Example HTML follows:

==================================================

<!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN>
<HTML>
<HEAD>
<META content=text/html;charset=iso-8859-1
http-equiv=Content-Type>
<style>

a:link  {text-decoration: none; }
a:hover {text-decoration: underline;}

.notes
{
    padding:        3px;
    margin:            10px;
    border:            1px solid #000000;
    background-color:                #779580;
    color:                #FFFFFF;        
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 11px;
}
h1
{

        font-family:       Verdana, Arial, Helvetica, sans-serif;
        font-size:         16px;
        font-weight:       bold;
        text-align:        left;
        color:             #000000;
        margin:            5px;
        margin-top:        5px;
        margin-bottom:     15px;
        padding:           3px;
        border-top:        1px solid #00662F;
        border-bottom:     2px solid #00662F;
}

.cellpalegreenb {
background-color: #C8F6A0;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: #000000;
padding: 5px;
}

.cellpalegreen {
background-color: #C8F6A0;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #000000;
padding: 5px;
}

.cellpaleyellowb {
background-color: #F7F8B8;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: #000000;
padding: 5px;
}

.cellpaleyellow {
background-color: #F7F8B8;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #000000;
padding: 5px;
}

.cellwhite {
background-color: #FFFFFF;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #000000;
padding: 5px;
}

.tableheader
{
    background-color:  #E7E5BB;
    padding:           2px;
    margin:            0px;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size:         13px;
    font-weight:       bold;
   
}

.titleBox {
border-color: #FFFFFF black;
background-color: #23A700;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 20px;
color: #FFFFFF;
border-style: solid;
border-top-width: 1px;
border-right-width: 0px;
border-bottom-width: 1px;
border-left-width: 0px;
padding: 5px;
}

.tabletop {
 border-color: #FFFFFF black;
 background-color: #23A700;
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: 15px;
 color: #FFFFFF;
 border-style: solid;
 border-top-width: 1px;
 border-right-width: 1px;
 border-bottom-width: 1px;
 border-left-width: 1px;
 padding: 5px;
}

.BodyBlack {
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: 11px;
 color: #000000;
}

.BodyWhite {
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: 11px;
 color: #FFFFFF;
}

.carded {
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: 10px;
 color: #FF0000;
}

.collection {
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: 10px;
 color: #099000;
 }

.international {
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: 10px;
 color: #CC33CC;
}

.delivery {
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: 10px;
 color: #000099;
}

.refused {
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: 10px;
 color: #4A809F;
}

.alert {
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: 11px;
 color: #FF0000;
 font-weight: bold;
}

.footer {
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: 10px;
 text-align: center;
 color: #3F874C;
}

.copyright {
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: 10px;
 color: #3F874C;
 position: absolute;
 bottom: 10px;
 }

</style>
</HEAD>
<BODY>
<table cellpadding=5 cellspacing=0 border=0 align=center WIDTH=100%>
<tr><td><h1>MailTrack Advice</h1></td>
<td width=178><a href="http://www.city-link.co.uk"><img src=cid:image1.230506.030303 alt="flying c" height=50 width=172 border=0></a></td>
</tr></table>
<DIV class=notes>Please find below the messages generated on your deliveries since your last mail at 13:50   today.
<BR>All of these messages were received in the last 60       minutes. <BR>
<BR>New Messages Received: 2</div><BR>
<TABLE cellpadding=2 cellspacing=2 border=0 align=CENTER <TR><TD class=tableheader>Account No.</TD>
<TD class=tableheader>Our Ref</TD>
<TD class=tableheader>Your Ref</TD>
<TD class=tableheader>Del Addr</TD>
<TD class=tableheader>Message (Click message header to REPLY)</TD>
</TR>
<TR><td  class=cellpaleyellow>875093</td>
<td  class=cellpaleyellow>PS906873</td>
<td  class=cellpaleyellow>LD15255</td>
<td  class=cellpaleyellow>MICHAEL BETTS<br>19 STRATHBURN GARDENS<br>INVERURIE<br><br><br>AB51 4RY<br></td>
<TD class=cellpaleyellow>
<TABLE cellpadding=2 cellspacing=0 border=0 width=100%
<TR><TD width=50%><a class=carded href=mailto:hailsham@city-link.co.uk?subject=Instructions%20for%20Job:%20PS906873%2014:22%200502 PREMISES CLOSED - TIME CARDED>
PREMISES CLOSED - TIME CARDED  (1) </a>
</TD>
<TD  width=50% class=carded>Door Description: BROWN DOOR<BR>
Carded Time: 14:22<BR>
LOG: 4333062<BR>
</TD></TR></TABLE></TD></TR><TR><td  class=cellpaleyellow>875093</td>
<td  class=cellpaleyellow>PS906867</td>
<td  class=cellpaleyellow>LD15262</td>
<td  class=cellpaleyellow>HIGHGATE STATIONERS & PRINTERS<br>5A CROGSLAND ROAD<br>LONDON<br><br><br>NW1 8AY<br></td>
<TD class=cellpaleyellow>
<TABLE cellpadding=2 cellspacing=0 border=0 width=100%
<TR><TD width=50%><a class=carded href=mailto:hailsham@city-link.co.uk?subject=Instructions%20for%20Job:%20PS906867%2016:18%200502 PREMISES CLOSED - TIME CARDED>
PREMISES CLOSED - TIME CARDED  (1) </a>
</TD>
<TD  width=50% class=carded>Door Description: GREEN<BR>
Carded Time: 16:18<BR>
LOG: 3821551<BR>
</TD></TR></TABLE></TD></TR></TABLE><BR><BR>
<CENTER><FONT class=footer>MailTrack V1.60 (04/05/2006) &copy; Initial City Link 2001-2006</FONT></CENTER>

<BR>
_____________________________________________________________________<BR>
The information contained in this e-mail is intended only for the<BR>
individual to whom it is addressed. It may contain privileged and<BR>
confidential information. If you have received this message in<BR>
error or there are any problems, please notify the sender<BR>
immediately and delete the message from your computer. The<BR>
unauthorised use, disclosure, copying or alteration of this<BR>
message is forbidden. This message has been checked for all<BR>
known viruses by Initial City Link prior to sending.<BR>
</BODY>
</HTML>

==============================================================

In this example two parcel deliveries have failed, and I want to extract the two sets of information and email them directly to my customer.

Any advice gratefully received.

Chris Bray.


0
Comment
Question by:chrisbray
  • 2
2 Comments
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 16930924
Ideally, You should use an HTML parser.
Unfortunately, the only "free" one I've seen is in the Jedi component (TjvHTMLParser)
However, this does not seem to work as simply as you would like.

If you expect the html to *always* be in the format you describe above, it is simple enough to write your own routine to get the data out, using POS()
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 125 total points
ID: 16931259
actually, there are many free html parsers available
http://www.torry.net/pages.php?id=216
I chose 1 at random ( THyperparser V1.0 http://www.torry.net/vcl/internet/html/hparse.zip )
put your html code in, and got enough info to parse your code in a nice fashion
I set a flag, and waited until I had seen 2 'TABLE' Tags
I then waited until the Header row was done ('/TR ' tag )
Every Row ( between 'TR' and '/TR') is a delivery line, so I treated each table cell as a field I wanted by using the Text values between 'TD' and '/TD'
if I found another 'TR' before the final '/TABLE', thenI knew there was "another delivery row"
When I saw a '/TABLE' - i stopped processing
Like I said, i chose 1 at random, but it did the trick. It was fast enough(although the demo displays slowly because it is not doing a .beginupdate or .endupdate for the TMemo)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
searching for DavidI's "Mobile Summer School download" 3 128
Convert Jpg /PNG To GIF 5 118
Help on project with Soap 10 48
Controlled Assessment GCSE - desperate help needed 4 75
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now