Creating Comment Notifications Using Actions And Triggers
When an author creates a post and a reader makes a comment on it, common courtesy is to respond to the comment. Aside from checking your post frequently, the only way you would know if a comment was created is to be notified in some way. In Drupal there are a couple of ways to achieve this. We will be discussing sending email notifications with Actions and Triggers since that is what the article is titled. In a previous article, Setting Up To Send HTML Email, we setup our email to handle HTML mail. You will want to review this article if you haven't done so yet.
- Mime Mail
- Mail System
- SMTP Authentication Support
In your Administration menu, go to Configuration>System>Actions.
This is the screen you should see:
In the Create An Advanced Action dropdown select Send HTML e-mail. Click Create. You will be brought to this screen:
In the above, all of the items in brackets are called tokens. Tokens are placeholders for data. This is great for data that changes such as article titles and author names. Fill out the page similar to what is above. Recipient can be a static email or a token. In the message section you can use static data and tokens. I threw in a few tokens that would probably not be in the message but are there to show what type of data the tokens contain. Above the Save button there is a browse available tokens link. This will give you a large list of tokens. I have found that some work and some do not. For example I tried to use node:author:mail for the recipient email and it didn't work. I found that comment:node:author:email did work. Overall, tokens are a very useful tool. When you have completed the page click Save.
Actions are functions that are intended to be run by triggers. The Trigger module is the interface that allows us to associate an Action with a Trigger. In the Administration menu go to Structure>Triggers.
On the right you will see the various types of triggers that can be created. Click on the Comment tab.
In the section, TRIGGER: WHEN EITHER SAVING A NEW COMMENT OR UPDATING AN EXISTING COMMENT, Select the action you created in the dropdown listed under system. Then click assign.
To test this out, create a post then log in as a test user. You should receive an email that is similar to the layout we created in Actions. Hopefully this will help in starting you off with sending emails using Actions and Triggers.