How can I use the Rules module in Drupal to auto send email reminders?

Best Answer

I had this situation happen in an events calendar web site - we wanted email reminders to be sent 5 days ahead of the event.

I set up the following process using the Rules module for Drupal 7:

1. In Rules, added a new component under the' Components tab'. The component plugin is "Action set". I named it "Send review event email to user". Under settings, I added two variables: variable "Node", label "Node", machine name "node", usage "parameter", and variable "User", label "User", machine name "user", usage "parameter". This permitted usage of node and user fields within the action of the component. Saved component.

2. Added an action, "Send mail" under "System". Filled out the form with the email details (you will see replacement patterns available for node and user fields). Saved the component.

3. Added a new rule, under the Rules tab. I named it "Send event review to user". Added two events:"After updating existing content of type Event" and "After saving new content of type Event". (Note, it is slightly confusing here, but the content type I was triggering on happened to be named Event). If you need to add conditions in order to limit the actions to specific nodes, you can add those (for example, I added: Entity is of type: node, Content is of type: Event, Data comparison: [node:field-rv-tier], Data value: Main). Added an action "Schedule component evaluation". In the form, I selected the component "Send review event email to user".My scheduled date was "-5 days", which means 5 days prior to the date field on the Event node I chose in the 'Scheduled Evaluation Date > data selector'. Added an identifier (useful to prevent duplicate reminders) "send event review for event [node:nid]" where [node:nid] made this identifier unique. Under User, entered "site:current-user" as the Data selector. This will pass in the user info to the component. Under Node, entered "node" as the Data selector. This will pass in the Event node info to the component. Now, the email is scheduled to be sent 5 days prior to the date of the Event date, once an Event node is either created or changed. As mentioned, the identifier is used by the Rules system to ensure only one scheduled component per unique identifier is queued for evaluation.

4. Created a rule to delete the scheduled component if the Event node is deleted. Added a new rule, "Delete Event Review Reminder". Add event: "After deleting content of type Event". Add action: "Delete scheduled tasks". Under component, select "Send review event email to user". Under identifier, copy and paste the identifier from the scheduled rule, "send event review for event [node:nid]". Set the weight of the rule to -1. Saved.

Updated: Nov 3 2017