New Approach of Mass Mailing

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
hunziker's picture

I like to present a new approach on how a subscription / notification mechanism can be implemented on a more generic layer. The concept is easy:
We are using Views to query the recipients, the subject, the body and so on. This query can be extended and manipulated by a user over the admin interface. The sending of the messages itself can be triggered by rules.
We have implemented this approach in a new module: Mass Messaging

The trick was to find a reliable solution. We do this by do a left join on the sent messages.

Advantages

The advantages of such a solution in contrast to Notification or Subscriptions are:

  • You can build up your own subscription framework with in minutes
  • It is a generic approach: Not all other modules need to be integrated. If the are integrated with Views, you can access all the need information.
  • It is reliable.
  • It is totally customizable.

A sample use case and the implementation

A simple use case is a subscription mechanism for a specific topic. You have a taxonomy called topic. Users can subscribe for certain topics (Terms). When new content is added to one of this topic the user receives a mail message with the new content. This use cases can be implemented by this module in the following way:

  1. Create a new taxonomy called "Topics"
  2. Add a Term Reference field to the user. (Configuration > Account Settings > Manage Fields) Use the "Topics" taxonomy. Call the field for example "subscribe to topics".
  3. Add a Term Reference field to the content type you want to make subscribable. Use the "Topics" taxonomy.
  4. Now the tricky part: Add a view. Use as the base entity "User".
  5. Add the new relation. Use the "subscribe to topic" field. Set the relation as required.
  6. Add relation to join in the nodes which has the same topic as the user has subscribe to. The field is called in our case "Taxonomy Term: Content with term"
  7. Add an contextual filter (aka argument) on the term id. If no result found, the view should be hidden.
  8. Add a second contextual filter on the node id.
  9. Define the subject (e.g. the node title), recipient (User Mail Address), Text Body (e.g. content body). Link this fields with the corresponding messaging settings.
  10. Save the view
  11. Create new rule. Use the event "After new content has been saved". Add a condition on which you check if the Term Reference field is defined.
  12. Add the "Send Mass Message" action. There you need to select the previous created View. As arguments you need to define on the first line the term and on the second line the node id.
  13. Save the rule.
  14. Test it!

This shows how easy you can build your subscriptions. In most cases you have never a more complicated case then the above.