简体   繁体   中英

What is the proper way to handle reminder emails?

My rails app will send a reminder email if a user has not composed any new posts in three days. This is defined as a rake task that is scheduled.

The task is scheduled every day. Of course, the task should only fire once for every user. A user should get it on the third day and then never again. On the tenth day, I might fire a totally different email.

  • Where and how to let the app know that a user has received the reminder?
  • Where, when and how to clean out the set "received reminder status" (if the user composes a new post)?
  • How to go about multiple reminder emails (eg after 5, 10, 15 days)?

I know that adding a column called received_reminder to the user table is an option. When you fire the task, you would change received_reminder to true and clean it out again when a user creates a new post. Multiple reminders would mean a new column for every reminder. Eg received_reminder_5days etc. – this seems not to DRY in opinion and I suspect that there might be a better way generally.

What is the best practice in terms of reminder emails?

You even do not need an extra field. You can set up an array reminder_days = [3,5,10,15] (for example) and then once a day check whether the age d (in days) of the users last post (which can be obtained from the database) is a member of reminder_days . If it is, you send a reminder. This reminder is the n+1 th reminder if n is the index of d in the array reminder_days .

To be really safe even in the case that the process of daily sending out reminder emails is interrputed, you could store the numbers of reminders that have already been sent in a field reminder_count . This field is set to 0 whenever the user creates a new post, and it is increased whenever a reminder is sent. With this field, you can check at any time whether a reminder still needs to be sent today or not (check whether n==reminder_count ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM