LISTSERV at Work
Tweet This
LISTSERV Tech Tip

Q: How can I configure my list to send out an after-hours auto-response to anyone who posts to it?

Recently, a customer asked how to send an auto-response to anyone who sent email to a public help list over the weekend when staff was out of the office. The intent was to assure senders that their messages had been received and were being worked on and to let them know that if the matter was urgent, they could call the person on duty. This auto-response should not be sent out during the week but only during a set time period on weekends.

This is fairly simple to accomplish with the list-level POSTACK1 mail template and a conditional block, although the coding of the condition can be a little complicated depending on how fine-grained you want the scheduling to be.

At its most basic, a LISTSERV conditional block consists of a structure that looks like this:

.bb expression
Text to send if the expression is true
.else
Text to send if the expression is false
.eb

The .bb, or "begin block" corresponds to an IF statement in most programming languages. The optional .else command allows the program flow to transfer to a second sub-block if the expression in .bb evaluates to FALSE. Finally, the .eb, or "end block" command closes off the structure and ends the conditional evaluation.

The .bb command requires an expression to evaluate, for example &WEEKDAY = 'FRI'. &WEEKDAY is a built-in LISTSERV template variable that contains the three-letter English abbreviation for the day of the week. So the possible values for &WEEKDAY are SUN, MON, TUE, WED, THU, FRI and SAT.

In between the commands is the text that LISTSERV will add to the auto-response message, depending on the evaluation of the expression in .bb.

To send an auto-response if the list receives a message during the weekend, a simple example would be as follows:

.bb ((&WEEKDAY = 'SAT') or (&WEEKDAY = 'SUN'))

All of the parentheses are required. This becomes more important in a moment.

The above statement will evaluate to TRUE on Saturday or Sunday. However, this may not be sufficient. The office closes at 6 p.m. (18:00:00) on Friday and opens at 9 a.m. (09:00:00) on Monday. This is a bit more complicated, but it makes use of another built-in template variable, &TIME, which outputs the current time in the 24-hour format "hh:mm:ss" – for instance, "01:23:45" or "16:32:54".

.bb (((&WEEKDAY = 'FRI') and (&TIME > '18:00:00')) or (&WEEKDAY = 'SAT') or (&WEEKDAY = 'SUN') or ((&WEEKDAY = 'MON') and (&TIME < '09:00:00')))

Again, all the parentheses are important and required. We are now evaluating four distinct date and time periods:

  • Friday after 6:00 PM (18:00:00)
  • All day Saturday
  • All day Sunday
  • Monday until 9:00 AM (09:00:00)

If any one of these evaluates to TRUE, the entire statement is TRUE, and we can now determine which block of text will be incorporated into the auto-response message.

.bb (((&WEEKDAY = 'FRI') and (&TIME > '18:00:00')) or (&WEEKDAY = 'SAT') or (&WEEKDAY = 'SUN') or ((&WEEKDAY = 'MON') and (&TIME < '09:00:00')))

Hello! We wanted to let you know that we've received your email with subject "&SUBJECT". We are working on your request, but if this is an urgent matter, please call the officer on duty at 1-800-555-5555, extension 555.

.else

Hello! We wanted to let you know that we've received your email with subject "&SUBJECT". We are working on your request and will respond to you as soon as possible.

.eb

The &SUBJECT variable in the text blocks inserts the text of the subject line from the original message.

Now that we have made the .bb line quite lengthy, the main thing to be aware of when building the .bb line is that it must be a single physical line. It can wrap in the editor, but it cannot contain any newline characters.

In other words, don't try to neaten it up like this as this will throw an error when executed:

.bb (((&WEEKDAY = 'FRI') and (&TIME > '18:00:00')) or
(&WEEKDAY = 'SAT') or
(&WEEKDAY = 'SUN') or
((&WEEKDAY = 'MON') and (&TIME < '09:00:00')))

And again, remember that all of the parentheses in the above example are required.

If you prefer not to send a response message during office hours, you can replace the text in the .else sub-block with the LISTSERV template command .qq, for example:

.bb (((&WEEKDAY = 'FRI') and (&TIME > '18:00:00')) or (&WEEKDAY = 'SAT') or (&WEEKDAY = 'SUN') or ((&WEEKDAY = 'MON') and (&TIME < '09:00:00')))

Hello! We wanted to let you know that we've received your email with subject "&SUBJECT". We are working on your request, but if this is an urgent matter, please call the officer on duty at 1-800-555-5555, extension 555.

.else

.qq

.eb

However, should you choose to do this, consider setting the list's "Ack" list configuration keyword to "Yes". Otherwise, during office hours, nothing will be sent back in response to a user's message, and the user might be left wondering if the message was received. Given that it's easy to send a different auto-response message rather than to simply cancel it altogether, our recommendation is that a response be provided in both cases, as we did in the first example.

Next Steps


© L-Soft 2020. All Rights Reserved.




Powered by LISTSERV Maestro