How to send an email once every 6 months using the Rules module?

by kashish   Last Updated January 03, 2018 13:07 PM

How to send an email once in every 6 months at 12:00 am for a date field about user renewal which is there in user profile using the Rules module?

Its mail should send in cyclic form every once in 6 months to notify user, repeating the mail once in 6 months.

So far I followed the tutorial "How to Send Follow-Up Emails Using Rules Scheduler in Drupal 7", and I have created a Rules Component, I then created a Rule like so:

  • Rules Event: After saving a new user account
  • Rules Conditions: None
  • Rules Action: schedule the Rules component (which I created before), with Scheduled evaluation date:+6 month and User > Data Selector: account.

So this is what I have done so far and this email I want to send every 6 months once repeatedly same email

Tags : 7 rules emails


Answers 1


The Rules module together with Rules Scheduler (a sub-module of it), can be used for sending such eMails, as explained in the steps below.

Step 1: Create a field to store the "next renewal" date

Add a field to the "user" entity with machine name (say) field_next_renewal. Allow only 1 date (to store the "next" renewal date).

Step 2: Create a Rules "Component"

Here is the Rules Component to be created (in Rules export format, just import it in your own environment via copy-paste):

{ "rules_send_email_notification" : {
    "LABEL" : "Send eMail notification",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "user_to_notify" : { "label" : "User to be notified", "type" : "user" } },
    "ACTION SET" : [
      { "mail" : {
          "to" : [ "user-to-notify:mail" ],
          "subject" : "Reminder about your next renewal",
          "message" : "This is a reminder about your next renewal on [user-to-notify:field_next_renewal] ...",
          "from" : "[site:mail]",
          "language" : [ "" ]
        }
      }
    ]
  }
}

Obviously, the Subject and Content of the eMail may need review / tuning, while you might also want to use some other From eMail ID.

Step 3: Create a "Rule" using the Rules Component

Here is the Rule to be created, in Rules export format (just import it in your own environment via copy-paste):

{ "rules_email_user_every_6_months" : {
    "LABEL" : "eMail user every 6 months",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "rules_scheduler" ],
    "ON" : { "user_insert" : [] },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "account" ], "field" : "field_next_renewal" } }
    ],
    "DO" : [
      { "data_set" : { "data" : [ "account:field-next-renewal" ], "value" : "+6 month" } },
      { "schedule" : {
          "component" : "rules_send_email_notification",
          "date" : {
            "select" : "account:field-next-renewal",
            "date_offset" : { "value" : 15552000 }
          },
          "identifier" : "[account:name]",
          "param_user_to_notify" : [ "account" ]
        }
      }
    ]
  }
}

The above rule refers to the Rules Component from the previous step.

Note that the 15552000 is the equivalent of 6 months in seconds. You may want to reduce that a bit, e.g. with a number of seconds equivalent to a few days (or a week or so). That way the eMail will be triggered a few days before the actual renewal.

Pierre.Vriens
Pierre.Vriens
September 30, 2015 10:55 AM

Related Questions


Simplenews condition results in double email

Updated December 05, 2017 22:07 PM


Send a link in an email

Updated December 08, 2017 19:07 PM


How do I send e-mail?

Updated December 19, 2017 14:07 PM