1

I want to send mail in every 7 days i.e please login site, you are not logged in since 7 days, only for those users which are not logged in since 7 days. I have already created an event i.e After creating new user a/c. But I don't think so that this event is good for existing users.

What event I need to add? What condition am I apply to check [account:last-login]<7 days & send mail in every 7 days.

Please Help. Thanks

enter image description here

7
  • 4
    Worth looking into Rules module. There is also another module drupal.org/project/inactive_user but, use it cautiously as there is no stable release for D7 but only dev. Also have a look at some of the great tutorials about Rules and sending email on NodeOne website by googling Reminders for inactive users NodeOne
    – Raf
    Sep 3, 2014 at 9:09
  • means inactive_user module may work in dev but no stable release for d7 @Raf
    – Nishant
    Sep 3, 2014 at 9:12
  • You can install the dev version of the module but, I don't know how stable is the dev version. But, what you need is Rules module, watch this tutorial nodeone.se/en/reminders-for-inactive-users, it is very handy and straight forward
    – Raf
    Sep 3, 2014 at 9:15
  • I am not getting clearly... that for existing user what event i need to add... @Raf
    – Nishant
    Sep 3, 2014 at 9:20
  • Once you understand Rules and Rules Scheduler (There are a tons of tutorials about it online, videos, etc.) then you can wrap your mind around how to resolve this issue. I can only guide you to the right path and you gotta find out how yourself (sorry, I am at work or I would have helped).
    – Raf
    Sep 3, 2014 at 9:41

1 Answer 1

6

In order to send an email to the user with 7 days of inactivity. Do the following:

A. Install Rules and Scheduler where Scheduler depends upon Tokens and Entity API

B. Once you have installed and enabled all the above modules, then you can start configuring your rule. To achieve what you want, do the following steps:

  1. Add new rule (Configuration -> Workflow -> Rules)
  2. Give it a name (i.e. user_login ) and select the event as "User has logged in", leave the tags field out and Save the rule
  3. After saving the Rule, go back to Rules using the breadcrumb (i.e. URL), when you are back in the Rules window, you should see your recently created rule (i.e. user_login)
  4. Select Component from top-right-hand-side-of-the-page (There should also be a tab named Scheduler, if not there then enable the module)
  5. Inside component, select Add new component
  6. Choose Action set as Component plugin and press Continue
  7. Give it a name (i.e. send_email_to_inactive_user)
  8. Skips Tag
  9. From Variables section, Choose DATA TYPE as User, give it a LABEL (i.e. inactive_user), give it a MACHINE name (i.e. inactive_user), ignore USAGE and press continue and the page should refersh.
  10. Now under Actions add an Action
  11. Select Send email
  12. TO, click on switch to Data Selector then reference the label of variable created in previous screen (i.e. inactive-user:mail) colon mail
  13. Provide a subject to your email
  14. Provide a message to your email
  15. Provide a from to your email
  16. Then save, now you should see the send_email action which is attached to the component.
  17. Go to the Rules and create an Action for your rule with event (User has log in)
  18. Select the value of action as Schedule component evaluation and it should open a window with combo box containing your recently created component (i.e. send_email_to_inactive_user), choose it
  19. for * Schedule Evaluation Date * provide a value (i.e. +10 minutes or +7 days or +15 weeks)
  20. for Identifier provide a value that will help you identify the scheduled task among other tasks (i.e. 7 days inactive reminder for [account:uid], where the [account:id] is replaced by the logged-in-users-id)
  21. Last option, select account for INACTIVE_USER's data selector
  22. Save and you should see the schedule component evaluation under Actions

You are done. If you pay close attention, the Rules evaluates The component when a User log in, the component then schedules an email to be send to the user +7 days (or override the existing one, updating the schedule time duration) and the scheduler sends the email when the time come. So Rule is used to evaluate the component and component is used to setup/update scheduler and scheduler is used to send the email.

In case you have not followed me, or can't figure out then here are my working sample exports for Rule & Component, just import them and change the values accordingly and save. Test it by logging in and then go to Configuration -> Workflow -> Rules -> Schedule and you should see a scheduled event for exactly (i.e. +7 days or +10 minutes from the time you login).

Important component first:

{ "rules_send_email_to_inactive_user" : {
    "LABEL" : "send_email_to_inactive_user",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "inactive_user" : { "label" : "inactive_user", "type" : "user" } },
    "ACTION SET" : [
      { "mail" : {
          "to" : [ "inactive-user:mail" ],
          "subject" : "test inactive user",
          "message" : "test inactive user message",
          "from" : "raf",
          "language" : [ "" ]
        }
      }
    ]
  }
}

then import the Rule:

{ "rules_user_login" : {
    "LABEL" : "user_login",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "rules_scheduler" ],
    "ON" : { "user_login" : [] },
    "DO" : [
      { "schedule" : {
          "component" : "rules_send_email_to_inactive_user",
          "date" : "+7 days",
          "identifier" : "7 days inactive reminder for [account:uid].",
          "param_inactive_user" : [ "account" ]
        }
      }
    ]
  }
}

Scheduled tasks for two users of the system Sample email

To test whether it is working you can execute it right away and you should get the email in your inbox.

Good luck man, if you needed further help, then Google is your best friend.

5
  • Awesome answer.. i think for query related rules, rules schedule this is the proper & best answer... Thanks a alot @Raf
    – Nishant
    Sep 4, 2014 at 5:29
  • @samzha welcome, glad it helped a bit.
    – Raf
    Sep 4, 2014 at 10:23
  • Once again thanks a lot @Raf & if anybody feels that this is a proper & correct way to solve that type of issue, please vote up this question, so it may help for those users who search this type of queries.
    – Nishant
    Sep 4, 2014 at 10:34
  • Hello, Raf, I have tried both the ways, but I am unable to get emails, Can you help me please?
    – Viraj
    Aug 31, 2015 at 11:38
  • 1
    very helpful +1
    – Iqbal
    Nov 8, 2016 at 7:21

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