Lasso Soft Inc. > Home

  • Articles

Scheduling Future Emails

The tip of the week for March 30, 2007 shows how to schedule emails to be sent in the future using Lasso. The tip includes updates to several LassoApps which make scheduling future emails easy.

Introduction

Sometimes it is beneficial to be able to schedule an email to be sent in the future. For example, if a visitor downloads a software demo from your site you might like to wait a couple days and then send them a reminder of how to buy the software. You might like to send a notification to the user about a flight or meeting at a specific time. Or, you might like to schedule reports overnight, but send the message including the report during the day.

This tip includes a modification to the [Email_Send] tag in Lasso 8.5 which allows a -Date parameter to be specified. The email will be queued up, but not actually sent until the date/time specified.

The modifications which are introduced in this tip will be included in a future update to Lasso 8.5.

Download

The download below contains new versions of the Lasso 8.5.2 Startup.LassoApp and SiteAdmin.LassoApp files.

<http://support.omnipilot.com/article_files/FutureEmail.zip>

Download the file and unzip it. Open the "Lasso Professional 8" application folder. Copy the "Startup.LassoApp" file into the "LassoStartup" folder. Copy the "SiteAdmin.LassoApp" file into the "LassoApps" folder. You can archive the older versions of the LassoApps if you want to be able to revert to the shipping version. Restart Lasso using "sudo lasso8ctl restart" or the Services control panel.

[Email_Send]

The [Email_Send] tag now accepts a -Date parameter. This parameter must be passed a [Date] object. If no -Date parameter is specified or the value passed to the parameter is not a [Date] object then the email will be sent with the current date/time.

The -Date parameter will be used for two purposes. It will be formatted as the Date header in the sent email message. If the date is in the past then the email message will be sent immediately. If the date is in the future then the email message will be held in the email queue until the specified date/time.

For example, the following message will be sent one day in the future at the same time as the message is being queued.

  [Email_Send:

      -To='example@example.com',

      -From='example@example.com',

      -Sujbect='Reminder',

      -Body='...',

      -Date=(Date_Add: Date, -Day=1)]

Canceling Messages

There are three methods which can be used to cancel queued messages which have not yet been sent. This might be important if you are asked not to send messages to an address, but have already queued messages for sending in the future to that address.

First, the Utility > Email section of Site Administration can be used to view the messages which are queued and individual messages can be deleted using the interface. However, this interface does not make it easy to find particular messages among the many which have been queued.

Second, the Utility > SQL section of Site Administration or normal [Inline] tags can be used to search the email queue. Select the "Lasso Internal" database and the "site" table. The following SQL statement would find all messages which are queued for the "example@example.com" email address.

  SELECT * FROM smtp_queue where mime_recipients LIKE "example@example.com";

 

The following SQL statement would delete all messages which are queued for the "example@example.com" email address.

 DELETE * FROM smtp_queue where mime_recipients LIKE "example@example.com";

Finally, the [Email_Result] tag can be used to store an ID for each email which was queued. If a collection of IDs are stored for a given user then the emails can be deleted later, but before they are sent. This code will store the ID of the queued message in a variable "id".

  [Email_Send:

      -To='example@example.com',

      -From='example@example.com',

      -Sujbect='Reminder',

      -Body='...',

      -Date=(Date_Add: Date, -Day=1)]

  [Var: 'id' = Email_Result]

With this stored ID the email can be deleted at any time before it is sent using a generated SQL statement like that shown below. Note that the unique ID is stored in a field id_site. In other tables this field is used to store the ID of the current site, but since each site has its own database this field was repurposed.

  DELETE * FROM smtp_queue where id_site = "' + $id + '"';

Limitations

The email sending system in Lasso attempts to send messages as soon after the specified date/time as possible. However, heavy email volume or transient SMTP errors can cause messages to be delayed by several minutes up to an hour.

The email queue is designed to store messages temporarily until they are sent. While Lasso can handle sending many thousands of messages the queue was not designed to store messages indefinitely.

I would not recommend using the -Date parameter to schedule messages more than about a month in advance. If you need to schedule messages far into the future it would be better to schedule those messages periodically using a scheduled event.

More Information

More information about all of the tags used in this example can be found in the Lasso 8.5 Language Guide or in the online Lasso Reference .
 

Author: Fletcher Sandbeck
Created: 30 May 2007
Last Modified: 16 Mar 2011

Comments

No comments found
You must be logged in to comment.

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft