I want to get the Email address of last comment's author. Actually, I want to send email by creating a rule when new comment posted and this email will go to the user who commented on node before this new comment.
There are two situations and they might be a bit hard to combine. Drupal has a concept of threading comments, where the last comment is not necessarily the last in line. Like this:
- Comment 1 - Comment 3 (reply to comment 1) - Comment 2
Who should get the mail? The poster of comment 2 (the last comment author), or user 1? Or both? Also note that you can disable threading comments on the content type settings page.
In order to send a mail to the author of Comment 1, you can create a Rule on After Saving New Comments. Use the Send mail action and for the
to: field you can use the token
[comment:parent:author:mail]. (The mail of the author of the comment above this one.)
If you want to send a mail to the author of comment 2, your rule gets a bit more complicated. The initial action need to be Before Saving New Comments (so last comment is actually the last comment before yours).
For the first action choose
Add a variable, the type is List of comments and you choose the value to be
comment:node:comments. This variable holds all comments on the node.
Now you need to find a way to keep removing items from this list and send an email to the last one.
Below is based on experience and not tested, but I guess you can add a loop and loop over the items in your newly created variable. Then, in the loop Add a variable to contain a comment entity and set it with the current item in the loop. This will redefine this variable for every comment in the list and in the end this variable will hold the last comment. Then below (not in) the loop, add your mail action and use the author of your newly created variable.
If you want to send a mail to all commenters, place the mail action within the loop (you can omit the comment variable in this case).
This can also cause the author of comment 3 to get a mail triggered by comment 4:
- Comment 1 - Comment 3 (reply to comment 1) - Comment 2 - Comment 4
If you want to have more control, you'll need to create a Rules Component and call that component from the loop. Within the component you can add conditions to check if the comment has parents and skip the variable assignment based on that.