How to automatically send an email to the users of your intervention

From Lifeguide Wiki
Jump to: navigation, search

Sending e-mails

How to automatically send an e-mail to your end-user

The formula for sending e-mails

To send an automated e-mail, use the command sendemail followed by a unique e-mail name, e-mail address, subject heading, e-mail content, and details of when you want the e-mail to be sent out (in that order).

Written Example of Logic:

show page2

sendemail (unique_e-mail_name, e-mail_address, "Subject message for e-mail", "E-mail content", number in seconds indicating how long after the end-user views pagename1 that you want the e-mail sent out)

Below is a break-down of each part of this logic:

Unique Name for the e-mail and email address

When the e-mail name is paired with an email address, it has to be unique for every single e-mail that you want to send out. So, if you are sending the same e-mail to every end-user, you can just choose a name for that email, like "welcomeemail" and when it is paired with an email address, this combination will be unique.

It becomes more complicated, however, if you want to send an email to a researcher, or other fixed person, relating to each end-user (e.g. if you need to send an e-mail each time an end-user finishes a session) or if an e-mail needs to be sent out each time an end-user responds to an interaction in a certain way (e.g. if their responses indicate that a health condition is getting worse). This is because the researcher has a constant email address, so if three end-users all reach the same point in the intervention, meaning that three e-mails will need to be sent to the researcher, the email name and email address combination will be the same in each case.

The best way get around this problem is to use the append command to attach the end-user’s username onto the unique name you have given to the e-mail message. You will then have a unique name for that e-mail.

So, in the example below, the username that the end-user provided on the login page of the intervention has been appended to the string "sessionfinish" to create a unique name for each of these emails that are sent out.

append (login.uname, "sessionfinish")

E-mail address

The e-mail address then needs to come next in the logic.

When sending e-mails to end-users, the e-mail address will be different for each person. The e-mail address will probably come from a previous interaction in the intervention. Therefore putting the page name and interaction name in this section of the logic will mean that this is the e-mail address that will be used (e.g. login.email, where email is the unique name of the interaction that asked end-users to type their e-mail which can be found on the page called login).

For sending e-mails to a fixed person such as a researcher, therapist or healthcare professional who is managing the intervention, the e-mail address can be typed as a string (e.g. "j.smith@uni.ac.uk")

Subject and e-mail content

These are the next two parts of the e-mail logic. Both need to be written as strings so will need to have quotation marks.

When writing the e-mail content you will need to use the phrase \n to put text onto a new line.

For example:

"For your chance to be entered into a prize draw for 100 pounds, please click on the link below or copy and paste it into the address line of your internet browser.\n http://www.virusdefence.org.uk/login \n Thank you."

The e-mail text will be presented as plain text which means you cannot use bold, underline or italic text and cannot change the size or font type. Also, some symbols cannot be included into the text such as pound signs (£) or ampersands (&). At present, these symbols will need to be written as words.

Using end-user’s details in the e-mail content

You can also include tailored feedback within the content of the e-mail using the append command. For example, the person’s username can be taken from the text entry interaction where they first entered it to put in the email content, by simply writing the page.interaction name into the logic (see example 1 below). Similarly, information from any text entry or numeric value interaction can be incorporated into e-mail content in the same way.

If you want to add scores that have been calculated from the interactions or responses to single/multiple choice interactions you will need to use the set function (see chapter 19).

When you want the e-mail to be sent out

The final part of the logic command refers to when you want the e-mail to be sent out. This number needs to be in seconds and relates to how long after the end-user has viewed the page mentioned before it that it should be sent. So if you want the e-mail to be sent after 24 hours this will be 86400 seconds.

Because of this time element, you can have a number of e-mails stored up after the end-user has visited the page. This is especially useful if you want to send out automated reminders to users throughout the course of using the intervention.

N.B. Our server send out emails every 5 minutes. If your emails are to be sent out for example, 30 seconds apart, you may receive all the emails at the same time.

The rest of this chapter provides two examples of logic for sending out automated e-mails; the first involves sending e-mails out to end-users and the second for sending e-mails out to a researcher (or other fixed person).

E-mail times at a glance

The following list provides a set of times and their corresponding number of seconds. For testing purposes, reduce the numbers to a shorter, more convenient time.

1 minute - 60

30 minutes - 1800

1 hour - 3600

12 hours - 43200

1 day - 86400

2 days - 172800

3 days - 259200

4 days - 345600

5 days - 432000

6 days - 518400

1 week - 604800

2 weeks - 1209600

3 weeks - 1814400

4 weeks - 2419200

5 weeks - 3024000

6 weeks - 3628800

7 weeks - 4233600

8 weeks - 4838400

9 weeks - 5443200

10 weeks - 6048000

15 weeks - 9072000

20 weeks - 12096000

25 weeks - 15120000

30 weeks - 18144000

35 weeks - 21168000

40 weeks - 24192000

45 weeks - 27216000

1 year - 31536000

Examples

Example 1: Sending e-mails to end-users

The logic in this example will send a welcome e-mail to each new-user after they have registered their details on the login page.

show login

  • Show end-users the first page of the intervention which has been given the unique name login

sendemail("welcomeemail", login.uname, "Welcome to the Lifestyle Study", append ("Thank you for registering for the study\n\n", login.uname, "\n\n Please remember to chart your daily progress.\n\n If you have any questions contact the researcher"), 30)

  • This is the logic command for sending out the e-mail. Once the end-user has clicked on the button on the login page an e-mail will be sent out. This logic needs to be written on one line (or broken up using ... – see chapter 14). This second append has been used to put the person’s username into the message that is being sent out to make it more personalised. This has been taken from the text entry interaction on the login page of the intervention.

Sending emails on a specific date

To send an email on a specific date, you will need to find the computer representation of that date. Computers represent time as the number of seconds elapsed since 1st January 1970 00:00:00 GMT, so for example, if you want to send an email at 1.00pm on 1st June 2012, you would have to first calculate how many seconds there are between 12.00am on 1st January 1970 and 1.00pm on 1st June 2012. You can use the following website to help you do this:

http://www.onlineconversion.com/unix_time.htm

Simply type the date and time you want the email to be sent into the boxes under the main heading: Convert a Date/Time to a Unix timestamp

Important: this is an American website, so you will need to enter the date in MM/DD/YYYY format rather than DD/MM/YYYY format.

Then subtract the current time (using the function currenttime) from the number you get from the website. The logic will look like this:

sendemail(unique name for e-mail, e-mail address, "Subject message for e-mail", "E-mail content", the number in seconds of the date you want the email to be sent – currenttime())

Example 1

If you want to send an email to end-users at 9:00am on 7th January 2011, type the date and time into the above website. This date and time is equal to 1294390800 seconds.

The logic to send an email at 9.00am on 7th January 20100 would be written like this:

sendemail(“welcomeemail”, login.uname, "Session 2", "Please log in to the website and complete Session 2.", 1294390800 – currenttime())