1

Required: Simplenews module in drupal7.

I have a content type student on my site. The student can be from department: Engineering, Management,....

What I want to do is whenever I add a student who is from engineering, a mail is sent automatically to subscribed users. I read about the simplenews module and already tried to send some mails which were received successfully.

What I can't do and am not finding information about is how to 'link' the term engineering in department to newsletter and then send a mail.

1 Answer 1

1

One reasonably straightforward way of doing that is with the Rules module.

Assuming there's only a few recipients, not hundreds...

You can use a "Send email" action to conditionally send an email to specified recipients.

Here's some example Rules that can be imported.

1. Basic "Send email" rule

{ "rules_send_email_notification_engineering" : {
    "LABEL" : "Send email notification (engineering)",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "Mail" ],
    "REQUIRES" : [ "rules" ],
    "ON" : [ "node_insert" ],
    "IF" : [
      { "AND" : [
          { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_department" } },
          { "data_is" : { "data" : [ "node:field-department" ], "value" : "engineering" } }
        ]
      }
    ],
    "DO" : [
      { "mail" : {
          "to" : "[email protected],[email protected]",
          "subject" : "New student record created [engineering]",
          "message" : "Sample message"
        }
      }
    ]
  }
}

You could also use the "Send mail to all users of a role" action in Rules to send to all users assigned to the "Engineering department" role, if such a role existed.

Update:

2. Create and send a simplenews newsletter with Rules

Here's how to create and send a newsletter with Rules:

{ "rules_send_email_notification_engineering" : {
    "LABEL" : "Send email notification (engineering)",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "Mail" ],
    "REQUIRES" : [ "rules", "simplenews_rules" ],
    "ON" : [ "node_insert" ],
    "IF" : [
      { "AND" : [
          { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_department" } },
          { "data_is" : { "data" : [ "node:field-department" ], "value" : "engineering" } }
        ]
      }
    ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "node",
            "param_type" : "simplenews",
            "param_title" : "New engineering student record created.",
            "param_author" : [ "site:current-user" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "data_set" : { "data" : [ "entity-created:status" ], "value" : "1" } },
      { "entity_save" : { "data" : [ "entity-created" ] } },
      { "simplenews_rules_action_send" : { "node" : [ "entity-created" ] } }
    ]
  }
}

You can set other field values on the newsletter node as required with the data_set action.

3
  • What if there are > hundreds recipients? Are there any modules out there to help me out?
    – Johan
    Oct 3, 2013 at 8:08
  • If there are hundreds of recipients, you could use the latter method of send to all users with a particular role. Oct 3, 2013 at 8:10
  • I just realized, you can create the newsletter node with Rules also. Just use the "Create a new entity" action. Answer updated to include that. Oct 3, 2013 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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