Tech Tip (LISTSERV Maestro) – Issue 4 – 2008
Q: How Can I Use Conditional Blocks to Deliver Customized Messages to Subscribers?
Answer by Ben Parker
Chief Corporate Consultant, L-Soft
A user of LISTSERV Maestro has a need to deliver customized notification emails to subscribers based on data fields they indicated interest in when subscribing to the list. The notification emails report lottery winning numbers, but there are 5 possible games and not everyone participates in all 5 games.
The desire is to send out one daily notification email with only the winning numbers for the games specified by each recipient. One way to do this is to send a different email message for each combination of games. This would require multiple different emails to compose and would also require multiple, slightly different SQL select statements to define the desired recipients, all with a high chance of making a simple mistake. Fortunately, there is an easier way. By using the conditional blocks feature in the message content, it is possible to do this all in one email message and with only one mailing job.
For this example, we will assume the following database structure:
Next we need to analyze the overall message content and separate it into blocks. Fortunately, it is already well designed with natural separator lines:
Since the overall email content will not change, only new winning numbers are inserted each time the job runs, it is easy to define each of the sections as drop-in content elements. The content of the lottery_main drop-in shows how this is done:
Within each section, the winning numbers are nested drop-ins, pulling their content directly from the lottery database. The draw date also has nested drop-ins for computing the day of the week from the actual drawing date.
We now have an email content definition that displays results for all games. Now we need to define the conditional content blocks that will cause the email to display the appropriate sections based on the T/F value for each game field as stored in the database for each recipient.
The syntax of a conditional block is composed of directives, conditional statements, and operators. A conditional block directive is coded by using ".bb" (begin block) and ".eb" (end block). There is also an ".else" directive not applicable in this case. Each directive must be on a line by itself, starting as the first character of the line. Conditional directives are not case sensitive. A conditional block always starts with the .bb directive followed by a "condition" or logical test on the same line. Field names used in a condition must be preceded by an ampersand ("&"). This means the logical test will be evaluated using the value of the data field for each recipient, but unlike mail-merge variables, conditionals are not followed by a semicolon (";") because they do not become substitutions. The conditional statement evaluates as true (T) or false (F), which determines whether or not this block will appear in this email for this recipient.
The .eb directive defines the end of the conditional block.
Since we have already defined each section as a separate drop-in, it becomes very easy to 'wrap' each section with an appropriate conditional statement, based on the database field values:
Now, since the conditional statements are not actually HTML code but must be placed in the correct location between the sections, when looking at the message content preview this can appear to be a little confusing:
So the best way to verify that the email is working as desired is to use a delivery test where you can choose different combinations of values:
And then verify that the correct results are received for each recipient:
The use of conditional blocks, while somewhat complex to set up, results in customized emails for all recipients. Everyone sees only the winning results for the games that they regularly follow. This allows one mailing job to serve the needs of all recipients, greatly simplifies the SQL select statement for defining the recipients pulled from the database and makes the most efficient use of bandwidth, ensuring timely delivery. This technique can also be useful for many other purposes, such as state or local sections within a national newsletter, for TV or cable programming guides, or for customer loyalty programs.
For more information on conditional blocks, see Section 6.9.2 and Section 17 of the LISTSERV Maestro Users Manual: