drupal1 Min Read

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

Gorav Singal

April 12, 2020

TL;DR

Set up a Rules reaction rule triggered by 'After saving a new comment' to send an automated email notification to the site admin.

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

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…

Share

Related Posts

Drupal 8 - How to Theme Form and its Fields with reordering fields

Drupal 8 - How to Theme Form and its Fields with reordering fields

Introduction In this post, we will see how to theme form and its fields…

Drupal 8 - How to create a Page with admin access and create its menu entry in Reports (No Coding)

Drupal 8 - How to create a Page with admin access and create its menu entry in Reports (No Coding)

Introduction I needed a report page, where I wanted to have some information…

Drupal: How to detect country and redirect to country specific website by using Cloudflare

Drupal: How to detect country and redirect to country specific website by using Cloudflare

Introduction Assume you have a drupal website and using cloudflare. You are…

Drupal - How to rename column of a content type

Drupal - How to rename column of a content type

Introduction You already have a content type with one or more fields in it…

Drupal 8 - How to hide help link About text formats and text format guidelines

Drupal 8 - How to hide help link About text formats and text format guidelines

Problem In drupal textarea field, it was always a pain to see the two links…

Drupal 8 Smart Image Style - Handle aspect ratio for small and long images

Drupal 8 Smart Image Style - Handle aspect ratio for small and long images

Problem Statement I’ve been using image styles, and heavily used “Scale and crop…

Latest Posts

Supply Chain Security — Protecting Your Software Pipeline

Supply Chain Security — Protecting Your Software Pipeline

In 2024, a single malicious contributor nearly compromised every Linux system on…

Security Ticketing and Incident Response

Security Ticketing and Incident Response

The worst time to figure out your incident response process is during an…

Security Mindset for Engineers — Think Like an Attacker

Security Mindset for Engineers — Think Like an Attacker

Most engineers think about security the way they think about flossing — they…

Secrets Management — Vault, SSM, and Secrets Manager

Secrets Management — Vault, SSM, and Secrets Manager

I’ve watched a production database get wiped because someone committed a root…

Penetration Testing Basics for Developers

Penetration Testing Basics for Developers

Most developers think of penetration testing as something a separate security…

OWASP Top 10 for Cloud Applications

OWASP Top 10 for Cloud Applications

The OWASP Top 10 was written for traditional web applications. But in the cloud…