1

What would be the preferred method to send an automated email to users that haven't logged in for a set amount of time? Let's say for a month. Are there any plugins that have this feature, or will it need a custom module created?

2

As far as I know there is no plugin that has this feature. If there is none you would have to write a custom module for that.

The module would have 4 main responsibilities.

  • get all users that are subject to get notified
  • compose a notification for each of them
  • send them (in a sync manner or as queue jobs, if you expect to have a lot of inactive users)
  • expose the above functionality as a console command

The users table has a column called lastLoginDate. You could use this to get the desired users. Then you could compose a notification by yourself, or you could use something like https://plugins.craftcms.com/notifications.

To get your module to do something you would use the console command called something like notifyInactiveUsers and call it from a Cron job that you setup on the server that Craft runs on.

PS: You would have to decide on the period the Cron job runs. Depending on that you could annoy your inactive users with too many notifications. To prevent that choose a longer period, or implement some kind of logic that keeps track of how many notifications an inactive user already received... oh boy.

1
  • Thank you @Johannes for your quick reply. Looks like I'll need to go the custom module route.
    – JBrew30
    Sep 20 at 15:04
3

Not sure if there is a plugin that does this automatically, but you can build a small module that accomplishes this. Since it should run automatically in the background, I would create the functionality as a custom console command and then execute that command regularly in a cron job (for example, daily or hourly).

The command would do the following:

  1. Check if there are any users who haven't logged in in the given time frame (check if current time minus last login login date is above the threshold for the reminder) AND haven't received this reminder yet.
  2. Send the email to those users (use the mailer service to send emails using the configured SMTP settings).
  3. Keep track of which users have been emailed already to prevent duplicate emails.

The last part is important to prevent users receiving multiple reminders. You can either store this information in a custom database table or just as a hidden field in your user accounts. The best option to store this information is a datetime field which stores the last time the reminder was set. This allows you to sent another reminder after a certain amount of time has passed. Also, if the user logs in after the reminder, you can later compare the last login date with the last reminder date – if the last login date is AFTER the last reminder date, the user becomes eligible for a login reminder once again.

1
  • thank you for solidifying my decision to go with a custom module.
    – JBrew30
    Sep 20 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.