0

So far, I've used Rules to unpublish a node 2 minutes after it is created or updated (testing for now). Now, I'm trying to send an email reminder to the node author 1 minute after the node is created or updated. So far, this is what I've done:

  • Create rules component >> action set "send email":

    • Scheduled evaluation date: node:changed
    • add offset: 1 minute
    • User node reminder: node:source:author (i also tried node:author).
  • Create new rule "schedule email publishing":

    • Event: After saving new content
    • Condition 1: content is of type: advertisement
    • Condition 2: content is published
    • Action: Schedule component evaluation: Rules Component: send email.

What am I doing wrong?

1

There are a couple of things in your Rule and Rules Component that are either wrong, or should be simplified, such as:

  • the scheduling part of it belongs in your Rule, not in your Rules component.
  • nowhere you have an "identifier" for the task to be scheduled (each scheduled task requires an identifier).
  • all your Rules Component should have to do, is to send an eMail to "some user" (= the node author in your case), indicated by a parameter of the component.
  • what should happen if the same node is updated twice in say 30 seconds?

Read on for an example of a Rule and Rules Component to achieve what you're trying to do.

Step 1:

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" : "Friendly eMail reminder (Subject)",
          "message" : "Friendly eMail reminder (Message body) ...",
          "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 2: 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, after you changed (twice) the machine name article to advertisement to fit your case; then change the rule from inactive to active):

{ "rules_send_email_reminder_to_node_author" : {
    "LABEL" : "Send email reminder to node author",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "rules_scheduler" ],
    "ON" : {
      "node_insert--article" : { "bundle" : "article" },
      "node_update--article" : { "bundle" : "article" }
    },
    "IF" : [ { "node_is_published" : { "node" : [ "node" ] } } ],
    "DO" : [
      { "schedule_delete" : {
          "component" : "rules_send_email_notification",
          "task" : "[node:author]-[node:nid]"
        }
      },
      { "schedule" : {
          "component" : "rules_send_email_notification",
          "date" : "+1 minute",
          "identifier" : "[node:author]-[node:nid]",
          "param_user_to_notify" : [ "node:author" ]
        }
      }
    ]
  }
}

Note that this rule refers to the Rules Component from the previous step. And it also includes an extra Rules Condition that the node must be published (similar to the Rules Condition in your question).

The schedule_delete that is part of this rule is to ensure that previously "scheduled" eMails will get removed when updating a node multiple times during a very short period like 20 seconds. That way it only triggers 1 eMail, and related to the most most recent update (imagine you add some extra data from the node content to the message body, in that case you don't want to eMail outdated information, right?).

Also important is the identifier you use for these scheduled tasks. In this case I used [node:author]-[node:nid] (= "author", followed by a "-" and then the nodes's "nid"). That way you have a unique task identifier for every node of each author.

Step 3: Review your timings

Rules Components scheduled for execution using Rules Scheduler, will actually be executed "next time cron runs" (after the scheduled date/time has arrived). So make sure to actually run cron and be patient enough for cron to have run.

Example: if you want to send the eMail after 1 minute, but cron only runs every 60 minutes, and the last cron ran 5 minutes ago, then you'll have to wait another 55 minutes before an attempt will be made for the eMail to be delivered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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