Can I use automation to send an email to someone who is mentioned in the comments?
Asked by Rob Brooks:

When an issue is moved to a new column, say from Backlog to In Progress, I'd like to send an email out to all parties involved, including any names that are "@Name" in the comments. Is this possible? Right now I'm getting this message when I try it:

![Jira Message.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/335003i520973C18D0BBE6A/image-size/large?v=v2&px=999 "Jira Message.jpg")

I'm totally new to using Jira automation, just discovered it this week, so any help would be very much appreciated!


Answers:
author: Bill Sheboy
body: Hi [@Rob Brooks](/t5/user/viewprofilepage/user-id/5541700) -- Welcome to the Atlassian Community!

What problem are you trying to solve by doing this notification on issue transition? That is, "why do this?" Knowing that may help the community to offer other suggestions.

Until we know that...

Although it is possible to scan all the comments to identify the mentioned users, and loop over them to send emails, that will be a **very slow rule** to process if you have several mentions. And, it is limited to up to 100 mentions spanning all comments.

An alternative would be to *automatically add the mentioned users in comments as watchers with an automation rule*, allowing the built-in notifications to do the email work. One advantage (or disadvantage, based on perspective) of this approach is it allows people to opt-out of the push notifications; sending the email directly will not allow this opting out, unless the person uses email rules in their email app to delete them.

Kind regards,  
Bill

comments: author: Rob Brooks
body: Hi, Bill, thanks. The reason behind this is because our issues are created by a power automate workflow, so the Reporter for everything shows as the creator of the workflow. we want the originator of the item (the person who fills out the Microsoft form) to be able to get updates as the issue is assigned or gets moved to new columns. Our organization is no longer supporting the version of Jira we're on so they won't add any new custom fields to this version. The new version is more restricted by our org and they won't let us set the board up the way we need it. I thought that if I could [@someone](/t5/user/viewprofilepage/user-id/1443884) then maybe I could base rules off of that.

So as you can see this is all a workaround issue. I do like the idea of adding them to the watch list. My next step I was about to look into was the notifications. If I can figure out how to make a rule that automatically assign a mention to the watch list, then I'll try that out.


author: Bill Sheboy
body: To add the watchers for the mentions, an example rule could be:

* trigger: comment added
* smart value condition:
  * first value: {{issue.comment.last.body.split(" ").match("\\\[\~accountid:(.\*)\\\]")}}
  * condition: does not equal
  * second value: *leave this empty*
* action: add watchers, using this smart value expression

```
{{issue.comment.last.body.split(" ").match("\[~accountid:(.*)\]").distinct}}
```

That works by splitting apart the last comment, helping the match to look for any mentions with their account id values, and finally returning the unique / distinct ones to add as watchers.


author: Nicolas Grossi
body: [@Rob Brooks](/t5/user/viewprofilepage/user-id/5541700) Welcome! You might take a look at this thread: <https://community.atlassian.com/t5/Automation-questions/How-send-email-to-user-mentioned-in-comment/qaq-p/2009432>

Nicolas

comments: author: Rob Brooks
body: Thanks, Nicolas. I did find this thread, but I'm definitely not competent enough yet to be able to do all that.


author: ALAA EDDINE ROUCADI
body: Hi [@Rob Brooks](/t5/user/viewprofilepage/user-id/5541700) ,

First of all, please consider the recommendations from [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) .

Regarding the error message you encountered, you can resolve it by:

* Using an intermediary variable, let's say **varEmailRecipient**, to store the email recipient.
* Validating the expression you are using by implementing a **Log Action** that displays the value of your variable.
* Using the intermediary variable in the **Send Email" action** by placing the value **{{varEmailRecipient}}** in the **To** field.

Regards,


Tags: cloud

jira-cloud