Database-Generated, HTML Email

JamesBowen

19+ years progress programming and still learning.
Ok, I want to generate a HTML email where the contents is sorced from the database. At the moment I'm storing the whole HTML page within my OE code.

This is becoming a pain because we/my boss has outsouced the email designed and I have to change the OE code everytime there is a new design change.

Where is the best place to store the HTML template Disk/Database/Code?

I have come-up with an hair brain idear by using webspeed to gernerate the HTML which is then ported back into the email message. This approche would mean creating a sockect connection to the web-server/wedpeed.

How would you tackle this?
 
Additional Question.

Could the OE DOM parser be used to edit an existing HTML page?
 
I have a solution to my own problem. :) I converted the the HTML email template into an XHTML. Theoretically an XHTML file is an XML document. Once having the XHTML file I was able to parse it using the SAX reader.

At the same time of parsing the file I created a new XML/XHTML file using the SAX writer, swapping out element values with those from the database.

My solution now means that the web developer can overwrite the email template without knowing any of ABL. The only thing changed was an "ID" attribute needed on some of the key html elements. I used the "ID" to know which elements value's needed to be populated.
 
As requested I have included a simple code example to generate HTML email.

Unpack the contents of the zip file. run xhtmlSaxDriver.p making sure the current/working directory is in your propath.

If it works then an HTML file should be created called output-email.htm.

Have fun.
 

Attachments

Quick Update.

I have not implemented my code into our Live production systems. During the testing phase we noticed that part of the email was having an "!" inserted into the xHTML. I found out that Linux/Unix sendmail was inserting the exclamation mark when the string length was greater than 2040 character long.

The xHTML file was created was a single line of HTML which is perfectly valid. I then enabled formatted attribute for the SAX writer, but under Outlook/IE the HTML was not begin rendered correctly due to spacing in the HTML.

My solution was to turn off formatting in the SAX witter and re-use Linux tidy command as shown:

Code:
DEFINE VARIABLE cInputLine AS CHARACTER   NO-UNDO.

ASSIGN 
          cOSCOMMAND = 'tidy -wrap 80 -asxhtml -f /tmp/emailerrors-$PPID.txt'.
          
        INPUT-OUTPUT STREAM email_out THROUGH VALUE(cOSCommand) NO-ECHO NO-CONVERT.

        PUT STREAM email_out UNFORMATTED mail_messhtml SKIP.
        
        ASSIGN
          mail_messhtml = ''.

        OUTPUT STREAM email_out CLOSE.

        REPEAT:
          cInputLine = ''.

          IMPORT STREAM email_out UNFORMATTED cInputLine.
          
          ASSIGN
            mail_messhtml = mail_messhtml + cInputLine + '~n'.

        END.
INPUT STREAM email_out CLOSE.
The tidy command line tool can be found at: http://tidy.sourceforge.net

I've realized that this tidy utility would be handy if it was built into OpenEdge.
 
Back
Top