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

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" : "example@example.com,example2@example.com",
          "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.

| improve this answer | |
  • What if there are > hundreds recipients? Are there any modules out there to help me out? – Johan Oct 3 '13 at 8:08
  • If there are hundreds of recipients, you could use the latter method of send to all users with a particular role. – David Thomas Oct 3 '13 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. – David Thomas Oct 3 '13 at 8:27

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.