Using rules to send an email x days after a user registers

Events happening in the community are now at Drupal community events on www.drupal.org.
geefin's picture

Hi,

Hoping someone can advise. I need a module(s) that can send an email to a new user x number of days after they register to the site.

Essentially, I have been tasked with creating a membership site with different levels of membership from basic to premier. When a user signs up as a basic (normal authenticated) user I need the site to email them automatically (ideally via cron) after a week if they haven't signed up to become a premier member.

I've looked at the newsletter (simplenews) with scheduler, messaging, bulk operations, rules and yet I'm still drawing a blank.

Is it possible that rules is the answer? If so, any guidance would be much appreciated, I'm reasonably comfortable with Drupal but the rules have me lost.

Cheers,
Graeme.

Comments

Rules scheduler!

itangalo's picture

The Rules project includes the Rules Scheduler module, which can do exactly what you want to achieve.
Like so:

  1. Create a rule set that sends an email to a user. (The user should be provided as an argument to the rule set.)
  2. Create a triggered rule that is triggered when a user logs in (or possibly creates a new account -- but this will log them in as well).
  3. Let the triggered rule execute an action 'Schedule name-of-your-email-rule-set'. Set the time of evaluation to '+ 7 days'. Make sure to give the scheduled rule a nice ID, something like 'Send reminder email to user [user:uid]'. (Be sure to download the Token module!)

This could be it, but you'll want yet another action in your triggered rule:

  • Create an action that deletes any scheduled rules with ID 'Send reminder email to user [user:uid]'. Give this action a weight so it is executed before the action that sets a new rule.

This last action will make sure that any scheduled reminders are deleted when the user logs in, and then a new reminder is scheduled 7 days from the log-in date. Clever, huh?

(This example is more or less a copy of the example that fago demonstrated at DrupalCon Paris, and made me seriously interested in this module. If anyone is interested.)

Good luck!
//Johan Falk, NodeOne, Sweden

Wow, many many thanks. I'll

geefin's picture

Wow, many many thanks. I'll try and get my head round the steps, so it is possible, it's just a case of understanding and implementing it. Thanks again! :)

Issue with Scheduling the Ruleset

robbie01's picture

@ Johan,
Thanks for insight information on this topic. I'm new to drupal started working on it since last 4 weeks . Your comments have helped me to understand the fundamentals clearly.

@ All, Even I'm trying to achieve a similar functionality but not able to. I see no entries on schedule page. Let me describe what I'm trying to do

I would want to send 2 emails in the period of 10 days once after 2nd day (promotional mail) and second mail after 8 days(reminder mail). From your comment above I see that this functionality can be achieved using Rules & Rules Scheduler.

Process I followed:

  1. Created a Rule Set.
    A) Gave Machine readable name and argument data-type as "USER"
    B) Entered the Label name and machine readable name. >> Save
  2. Add new rule
    A) Gave a name to the rule, selected the rule set >> Save
    3) Gave a action "Send a mail to the user" >> Save (No condition, in fact tried both with and without condition)
    4) Filled in information about sender(site-wide address), Subj and Message.

Went ahead to create Triggered Rules ...

5) Add new rule
6) Gave in the Label and for Event I selected "User account has been created" >> Save changes
7) Under Rule Elements
A) Selected action with Rule scheduler, Schedule
B) Under Argument configuration Registered user , gave in the identifier and scheduled evaluation date as "+ 2 days" >> Save
8) Then gave a Condition saying if a user belong xyz role do the action.(arguments configuration: Registered user, also tried acting user)

After following the steps, I go to 'admin/rules/rule_sets/scheduling' , i see an empty page.

Can anybody suggest me where am i going wrong ? Also what is different between Registered and acting user in this case)

But I notice that when I do not give argument as "user" in rule set, I see that Rule set is displayed in schedule page under manual with no arguments.

I want this Rule to be be active always until I make any further change. Presently the way Rule is configured i feel(with lack of exp) rule will run only once.

Any tips to get this to work ?

@ Johan, how imp is identifier , since you say "'Send reminder email to user [user:uid]'" , isn't just meant to be for identifying purpose.

Thanks in advance.

Awesome community to be a part off :), cheers.

Tried creating accounts?

itangalo's picture

-0-
@robbie01: Great to see you in the community! Trying to take on Rules in the first month of Drupalling is impressive! I hope you keep up the work.

-1-
It seems you're doing everything right, so the only explanation I can find as to why no scheduled rule evaluation appears is that the triggered rule isn't triggered. Have you (or anyone else) created any accounts?

Maybe you have some problems with the conditions. Try removing any conditions, and see if it works.

I'll make a rule doing what you ask for and wrap it up in a Feature -- I'll paste the link when it's done. Then you can install it and see any differences in our configuration.

-2-
The identifier is important for two things, I think. The first is to be able to remove a task without execute it -- you'll then have to specify its identifier. The other one is -- I think -- more important. I think that Rules Scheduler removed any existing tasks with the same ID when it adds a new one. (I'm not sure about this, but I've seen some results suggesting this.) Thus, if you use the same identifier for different tasks, only the one added last will be executed.

Good luck!
//Johan Falk, NodeOne, Sweden

EDIT: Feature can be found here! http://groups.drupal.org/node/67103

update on scheduling issue ..

robbie01's picture

@ Johan

Thanks a ton for the feature and sharing some wonderful info.

To answer your question if I created a new users, Yes I did both programatically and manually. Like you mentioned when I removed the conditions scheduling list started populating. Thanks :) But what could cause such behavior? should having a condition in a Rule instead of Trigger solve this problem?any way I will try and let you know.

The functionality I'm trying to implement is I ask the users to fill out a webform and take the inputs of the webform to create a user and assigned him a particular role on the fly. And by using the rules module I was thinking of mailing the users at regular intervals. So for me assigning a condition in a trigger is a MUST I believe i.e a condition if a user belongs to XYZ ground, send him emails else do nothing. Is there any prerequisite before using an condition. Any suggestions

Also I noticed in your feature that under one rule set there are two rules for sending an email, why is it that two rules are configured?

Many Thanks.

Btw loved your vid on rules @ nodeone.

Glad to help! The conditions

itangalo's picture

Glad to help!

The conditions in Rules should be sufficient to do what you describe, so my guess is that something's wrong with how your conditions are configured. One possibility is that you're trying to check conditions (roles) for a user that is not yet created, which will make the user appear as anonymous to Rules. Check the following:
a) Do users already have accounts when they fill out the webform? If so, does Rules take this into account?
b) Are you trying to access data in the webform that Rules can't seem to get? Or are you running conditions on other variables that might not be available?

//Johan Falk, NodeOne, Sweden

PS: Thanks for the feedback on the Rules screencast! I'll try to post more stuff in English in the future.

@ Johan, Sorry for following

robbie01's picture

@ Johan,

Sorry for following up so late.

I see that the conditions are being ignored when the schedule list is being populated i.e I put a condition in select roles as, apply action only IF the user has Authenticated user and Dummy user role. I selected "All" in Match against any or all ....... (Dropdown list). While I'm creating a user manually I select "Dummy user" and "Authenticated user" is checked by default, still the list is not being populated.

Also I see that when I create a user with "Main User"(another role) and "Authenticated user(by default checked) role, the tables in DB show that new user is only associated with "Main user" and there is no reference to Authenticated user. So does that mean while selecting roles I can only select the custom roles and leave authenticated user unchecked?

What would be the right way to make a rule for this scenario:

I have two custom roles, Direct User and Indirect User.

I want a condition where IF user being to "Direct user role" do an action of running thr rule set. ??

I tried making a rule which says IF user belongs to Direct User role and Authenticated user do action , is including Authenticated user necessary?(i tried without also).

Awaiting your reply. Need help badly.

Thanks.

Rule evaluates on scheduled time

itangalo's picture

I think the rule/feature I posted added a reminder for all users, but checked for roles at the time when the rule is evaluated. It seemed sensible, since the user (I guess) change his/her role between account creation and the sending of the e-mail. However, it should be possible to add a condition on the triggered rule as well to avoid any pre-qualified user to be added to the scheduling queue.

Concerning which roles to run conditions on, I would suggest only marking the 'premium' roles -- those are the important ones. If the user belongs to any of the marked roles, the rule shouldn't be executed.

Good luck!
//Johan Falk, NodeOne, Sweden

Thanks

mewren's picture

Perfect. Just what I needed. I used this to schedule when a CCK node had not been updated in 6 months. I also created a "chain" reminder rule to the moderators on the rule set to schedule another email to the them know the content is very stale.

Don't forget to add the actual rule to send the email to the rule set. (click on the rule set , then "add a new rule").

Ended up with:
Triggered rule when content updated (delete all author reminder emails, delete all moderator reminder emails, schedule author reminder email)
Rule set for author reminder (send email, send copy to moderator, and schedule next reminder)
Rule set for moderator reminder (send email)

Thanks
Jen

Jen

Drupal 7 version

pandersb's picture

To update this post for Drupal 7.23 with Rules 7.x-2.3:

In Rules,

  • Add a new component under the Components tab. The component plugin is "Action set". Call it "Send email to User". Under settings, add a variable "User", label "User", machine name "user", usage "parameter". Save component.
  • Add an action, "Send mail" under "System". Fill out the form accordingly. Save the component.
  • Add a new rule, under the Rules tab. Call it "Send email to new user". Add an event:" After saving a new user account". Add an action "Schedule component evaluation". In the form, select the component "Send email to User". Specify your scheduled date, like "+2 weeks", which means 2 weeks from creation of new user. Add an identifier (this is useful as a pointer when you create the rule to delete the scheduled email when the user logs in before the 2 weeks.) Something like, "send email to new user [account:uid]" where [account:uid] makes this identifier unique. Under User, write "account" as the Data selector. This will pass in the user info to the component.

This will send the email after 2 weeks of user creation.
Now, you have to create a rule to delete the schedule when the user logs in before 2 weeks.

  • add a new rule, "Delete new user reminder". Add event: "User has logged in". Add action: "Delete scheduled task". Under component, select "Send email to User". Under identifier, copy and paste the identifier from the scheduled rule, "send email to new user [account:uid]". Save.
  • Set the weight to -1. Or set it to run before the email is sent. I can't recall why this is important. Look at the post above.

This is all dependant on how Cron is configured. I tried with 5 mins and there was over an hour delay because Cron ran every hour.

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: