Answers.Body: <p>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.</p>
  <p>The module would have 4 main responsibilities.</p>
  <ul>
  <li>get all users that are subject to get notified</li>
  <li>compose a notification for each of them</li>
  <li>send them (in a sync manner or as queue jobs, if you expect to have a lot of inactive users)</li>
  <li>expose the above functionality as a console command</li>
  </ul>
  <p>The <code>users</code> table has a column called <code>lastLoginDate</code>. You could use this to get the desired users. Then you could compose a notification by yourself, or you could use something like <a href="https://plugins.craftcms.com/notifications" rel="nofollow noreferrer">https://plugins.craftcms.com/notifications</a>.</p>
  <p>To get your module to do something you would use the console command called something like <code>notifyInactiveUsers</code> and call it from a Cron job that you setup on the server that Craft runs on.</p>
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-20T15:04:27.170Z
Answers.Text: Thank you @Johannes for your quick reply. Looks like I'll need to go the custom module route.
Answers.UserDisplayName: JBrew30
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-20T14:32:50.603Z
Answers.LastActivityDate: 2021-09-20T14:32:50.603Z
Answers.UserDisplayName: Johannes
Answers.Body: <p>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 <a href="https://craftcms.com/docs/3.x/extend/commands.html" rel="nofollow noreferrer">custom console command</a> and then execute that command regularly in a cron job (for example, daily or hourly).</p>
  <p>The command would do the following:</p>
  <ol>
  <li>Check if there are any users who haven't logged in in the given time frame (check if current time minus last <a href="https://docs.craftcms.com/api/v3/craft-elements-user.html#public-properties" rel="nofollow noreferrer">login login date</a> is above the threshold for the reminder) AND haven't received this reminder yet.</li>
  <li>Send the email to those users (use the <a href="https://docs.craftcms.com/api/v3/craft-mail-mailer.html" rel="nofollow noreferrer">mailer service</a> to send emails using the configured SMTP settings).</li>
  <li>Keep track of which users have been emailed already to prevent duplicate emails.</li>
  </ol>
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-20T15:06:04.117Z
Answers.Text: thank you for solidifying my decision to go with a custom module.
Answers.UserDisplayName: JBrew30
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-20T14:25:04.540Z
Answers.LastActivityDate: 2021-09-20T14:25:04.540Z
Answers.UserDisplayName: MoritzLost
Body: <p>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?</p>
  
Tags: <craft3><plugins><users><emails>
Title: Send automated emails to users that haven't logged in for X amount of time
ThreadText: # Send automated emails to users that haven't logged in for X amount of time
  
  (Asked by: username_0 on 2021-09-20)
  
  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?
  
  **Tags:** craft3, plugins, users, emails
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2021-09-20. Score: 2 | Accepted answer
  
  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.
  
  > **Comments:**
  > **username_0**: Thank you @username_1 for your quick reply. Looks like I'll need to go the custom module route.  
  
  ---
  
  ### Answer by username_2 on 2021-09-20. Score: 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](https://craftcms.com/docs/3.x/extend/commands.html) 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](https://docs.craftcms.com/api/v3/craft-elements-user.html#public-properties) 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](https://docs.craftcms.com/api/v3/craft-mail-mailer.html) 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.
  
  > **Comments:**
  > **username_0**: thank you for solidifying my decision to go with a custom module.  
  
  ---
  
  