How to send multiple follow-up emails at prespecified timepoints 🔗

When running a long-term study, it's common to need to send emails to participants at regular intervals or at predetermined times. As you may recall from the manual, you can use the *repeat keyword to repeatedly run any block of code, including (for example) scheduling emails to be sent. And to schedule an email to be sent sometime in the future, you can use the *when keyword (under *email ) to specify a date and time to send the email. One important thing to remember, however, is that using the *when keyword requires you to specify a time and date in the future . In other words, you cannot set the value of *when to be calendar::now ; you must schedule the email at least 1 second out in the future, like *when: calendar::now + 1.seconds .

Example of how to schedule and send multiple follow-up emails 🔗

In this example, we use *repeat to schedule weekly follow-up emails. Note especially how we increase the timeToSend value in each iteration of the repeat loop by adding 1.weeks to it each time.

>> emailNumber = 0
>> timeToSend = calendar::now + 1.minute

*repeat: 11
	*email
		*to: {theirEmail}
		*identifier: email{emailNumber}
		*when: timeToSend
		*subject: Invitation to weekly tests - week {emailNumber}!
		*body
			Hello again!

			Here is the link for your study questions for day {emailNumber}!

			https://www.guidedtrack.com/programs/{runcode}/run?participantID={participantID}&emailNumber={emailNumber}&week={emailNumber}

			Thank you so much for your responses!

	>> emailNumber = emailNumber + 1
	>> timeToSend = timeToSend + 1.weeks

Next: