The standard method of sending reports via email causes the report to be sent as an attachment to the letter. Someone, though, wanted to see how to include data in the body of the email. Following is an example of what I call masochistic programming, as it is very tedious. Basically, one has to combine data from Priority along with HTML coding; I imagine that the skill of hand-written HTML code has long disappeared, and even if it were still extant, the majority of Priority programmers have never come across it.
OK: down to work. The following example will include some data from a customer order, whose internal number can be found in the variable :$.ORD. First off, one has to link a few tables, then insert what will be the header to the letter.
LINK GENERALLOAD TO :$.GEN; ERRMSG 1 WHERE :RETVAL <= 0; LINK MAILBOX TO :$.MBX; ERRMSG 1 WHERE :RETVAL <= 0; :LINE = 1; INSERT INTO GENERALLOAD (LINE, RECORDTYPE, TEXT, TEXT2) SELECT :LINE, '1', ORDNAME, :GROUP FROM ORDERS WHERE ORD = :$.ORD;
:LINE = :LINE + 1; INSERT INTO GENERALLOAD (LINE, RECORDTYPE, TEXT) VALUES (:LINE, '2', '<HTML><BODY><dir=ltr><P>); :LINE = :LINE + 1; INSERT INTO GENERALLOAD (LINE, RECORDTYPE, TEXT) VALUES (:LINE, '2', STRCAT ( 'Customer number: ', CUSTOMERS.CUSTNAME, ' Customer name: ', CUSTOMERS.CUSTDES, ' Order date: ', DTOA (ORDERS.CURDATE, 'DD/MM/YY'), '<BR>'); :LINE = :LINE + 1; INSERT INTO GENERALLOAD (LINE, RECORDTYPE, TEXT) VALUES (:LINE, '2', STRCAT ('<TABLE>', '<tr><th>Line</th><th>Part number</th>', '<th>Part description</th><th>Quantity</th></tr>'); INSERT INTO GENERALLOAD (LINE, RECORDTYPE, TEXT) VALUES (:LINE + SQL.LINE, '2', STRCAT ( '<tr><td>', ITOA (SQL.LINE), '</td><td>', PART.PARTNAME, '</td><td>', PART.PARTDES, '</td><td>', RTOA (ORDERITEMS.QUANT, 2), '</td></tr>') FROM ORDERITEMS, PART WHERE ORDERITEMS.PART = PART.PART AND ORDERITEMS.ORD = :$.ORD; SELECT MAX (LINE) INTO :LINE FROM GENERALLOAD; :LINE = :LINE + 1; INSERT INTO GENERALLOAD (LINE, RECORDTYPE, TEXT) VALUES (:LINE, '2', '</TABLE></BODY></HTML>');
:EFILE = 'C:/TMP/2.TXT'; /* one has to define a suitable interface */ EXECUTE INTERFACE 'TEST_SENDMAIL', :EFILE, '-L', :$.GEN; SELECT MESSAGE INTO :PAR1 FROM ERRMSGS WHERE USER = SQL.USER AND TYPE = 'i'; ERRMSG 99 WHERE :RETVAL > 0; :MB = 0; SELECT ATOI (KEY1) INTO :MB FROM GENERALLOAD WHERE LINE = 1; INSERT INTO MAILBOX SELECT * FROM MAILBOX ORIG WHERE MAILBOX = :MB; :XMSG = ''; EXECUTE SENDMAIL :$.MBX, :XMSG; /* send it */ UNLINK MAILBOX; UNLINK GENERALLOAD;
No comments:
Post a Comment