Drupal 8 Rules module - How to configure Rules module to send email notification for every comment posted

April 12, 2020

Introduction

In our previous post, where we saw How to configure comments module

In this post, we will see how we can use Rules module to get email notification for each comment posted.

Configure Rules module

  • Goto /admin/config/workflow/rules
  • Add reaction Rule
  • In React on event, select After saving a new comment
  • Give it a label (title)
  • Now, add an action: Send email
  • In Value, put your desired email
  • Write a subject, message
  • Write reply-to (only If you are using ses-mailer module, it is important to set this field.)
  • Save it, save rule.

That is it. Now, when someone write a comment. You will get an email notification. Rules is very powerful and handy module. It has lot of workflows, and you can configure email notification for a number of workflows.

Important to note that, this module is not having good documentation. And to add tokens or the variables in the mail, traditional tokens will not work. You need to use twig conventions.

See examples:

  • To include title of node in mail
{% raw %}
{{ node.title }}
{% endraw %}
  • To include url alias of node
{% raw %}
{{ comment.entity_id.entity | entity_url }}
{% endraw %}
  • You can mix english sentence with twig:
{% raw %}
New comment posted at {{ comment.entity_id.entity | entity_url }}
{% endraw %}

Hope it helps. Thanks for reading…


Similar Posts

Latest Posts