Sending Emails

From Lifeguide Wiki
Jump to navigation Jump to search

Sending e-mails

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

The formula for sending e-mails

To send an automated e-mail, the same set of logic commands are used. The logic uses 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:

after pagename1 if sendemail (unique name for e-mail, 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) goto pagename2

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

after login if 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) goto page1

  • 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:

after pagename1 if 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()) goto pagename2

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:

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

Example 2: Sending e-mails to researchers/therapists

This example illustrates how to send an e-mail automatically to the person overseeing the intervention if the end-user responds in a particular way to an interaction. For example, if you had an intervention for individuals who are depressed, you may incorporate standardised instruments to measure symptom severity. This example is based on the use of the Beck Depression Inventory-II (BDI-II). A person can score between 0-3 on any item in the measure with 3 indicating high symptom severity. If a person scores 2 or 3 on item 9 (relating to suicide) it is usually an indication that intervention from a trained therapist is required. The logic in this example shows how an automatic e-mail can be sent to the clinician detailing the username of that person if they scored 2 or 3 on this item. If the end-user scored 0 or 1 on this item the e-mail would not be sent.

show bdip2

  • Show end-users the page that includes items from the BDI-II

after bdip2 if (or (bdip2.bdi9 = "bdi92", bdip2.bdi9 = "bdi93", sendemail (append (login.uname, "bdi"), "jsmith@uni.ac.uk", "bdiscore", (append (login.uname, " has scored high on bdi item 9")), 60))) goto depresswarn

  • This is the logic command for sending out the e-mail. Once the end-user has clicked on the button on the page an e-mail will be sent out. This logic needs to be written on one line. So, after they have been to the bdip2 page, if they responded to the bdi92 or bdi93 item (which refers to a score of 2 or 3 on item 9) then, after 60 seconds, an e-mail will be sent out to the researcher. This e-mail will detail the username of the end-user and will tell the researcher that they scored high on bdi item 9.

show depresswarn

  • The end-user will then be sent to a page entitled depresswarn.

Cancelling e-mails that have been set up

There may be times when you need to cancel an e-mail that you may have set up. For example, if you have a number of sessions in your intervention and you wanted to send an e-mail to remind people if they do not log on to the next session, then you may set up an e-mail reminder to ask them to do so. However, if they do log onto the session before the reminder is sent out then you can set the logic up to cancel the email.

The logic for cancelling an e-mail includes the command cancelemail followed by the unique e-mail name and the e-mail address. A basic written example of this logic would be:

after login2 cancelemail(unique name for e-mail, e-mail address) goto page1session2

The logic command will be written differently depending on where the e-mail address needs to be located (i.e. whether they use their e-mail address every time they log in to the intervention or if the e-mail address needs to come from the first time that they signed up to the intervention). Examples of the logic for these two possibilities are provided below.

Example 3: Cancelling an e-mail where the e-mail address is used to log-in to the intervention

A demo accompanying this example can be found on the LifeGuide Community site entitled Email Example 3. Note that for testing purposes the time for sending the e-mail has been set to 10 minutes (600 seconds).

show welcome

show signin

  • Show end-users the first page of the intervention which has been given the unique name welcome. This page consists of a link to either a signin page for new end-users to sign up for the intervention or a login page for registered end-users.

after signin if sendemail ("reminder1", signin.email, "Stress Less: Session 2", "This is your one week reminder for the Stress Less intervention", 352800) goto page1

  • After the end-user has signed up to the intervention, a logic command is then set up to send an e-mail to them 1 week (or 352800 seconds) after they first visited this page to remind them to go back to the intervention for the next session. The unique name for this e-mail consists of the end-user’s username appended to the string reminder1. The e-mail address is taken from an interaction on the signup page that is uniquely named email.
  • This logic would be written all on one line or can be broken up into two lines using …

show page1

show page2

show page3

  • These pages represent the first session (of course one session is likely to be much longer than this).

show endsession1

  • This is the last page of the session that encourages end-users to close the site and work on their goals for the week. Alternatively, users have a chance to skip straight to session 2 by clicking on a jump button that takes them to the sess2p1 page.

show login

show sess2p1

  • If end-users select the login button on the welcome page they will go straight to the login page. Once logged in they will then go to sess2p1.

after sess2p1 if cancelemail ("reminder", login.email2) goto sess2p2

show sess2p2

  • If an end-user visits the sess2p1 page before the time specified on the sendemail command, then the e-mail will be automatically cancelled. This is the logic for cancelling the e-mail (again, this should be written on one line). The unique e-mail name is the same as the unique name in the sendemail command above and the e-mail address is taken from the interaction on the signin page.
  • NB: This logic works on the notion that the person uses their e-mail address to log in to the session.

Example 4: Cancelling e-mails when the e-mail address needs to be taken from an earlier session of the intervention

show welcome

show signin

  • Show end-users the first page of the intervention which has been given the unique name welcome. This page consists of a link to either a signin page for new users to sign up for the intervention or a login page for registered users.

after signin if and (sendemail ("reminder1", signin.email, "Stress Less: Session 2", "This is your one week reminder for the Stress Less intervention", 600), ... savevalue (signin.uname, "email", signin.email)) goto page1

  • After the end-user has signed up to the intervention a logic command is then set up to send an e-mail to them 1 week (or 352800 seconds) after they first visited this page to remind them to go back to the intervention for the next session. The unique name for this e-mail consists of the end-user’s username appended to the string reminder1. The e-mail address is taken from an interaction on the signup page that is uniquely named email.
  • Here the savevalue command is used to save the e-mail address of the end-user against their username so that the e-mail address can be loaded in subsequent places in the logic.

show page1

show page2

show page3

  • These pages represent the first session (of course one session is likely to be much longer than this).

show endsession1

  • This is the last page of the session that encourages end-users to close the site and work on their goals for the week. Alternatively, users have a chance to skip straight to session 2 by clicking on a jump button that takes them to the sess2p1 page.

show login

show sess2p1

  • If end-users select the login button on the welcome page they will go straight to the login page. Once logged in they will then go to sess2p1.

after sess2p1 if cancelemail ("reminder", loadvalue (signin.uname, "email")) goto sess2p

show sess2p2

  • If an end-user visits the sess2p1 page before the time specified on the sendemail command then the e-mail will be automatically cancelled. This is the logic for cancelling the e-mail (again, this should be written on one line). The unique e-mail name is the same as the unique name in the sendemail command above, and the e-mail address is loaded from the information that has been saved as email which was taken from the interaction on the signin page.