Accessing recipient email in Velocity email template

Hi,

Want to check the email addtess of the recipient in my JIRA and based on the email if the email contain "ext" that is external email id , i need to print the comment in the notification. If otherwise Email should only contain JIRA ticket link as internal user can access it via that link.

I am new to this velocity templates but

$recipient.getEmail() will return a string ? Can I compare it? Is there proper APIs where I can learn and test these templates?

Thanks,

Kalyani

1 answer

1 accepted

Accepted Answer
0 votes

$recipient.getEmail() should return a string, from memory. That means you should be able to use $recipient.getEmail().toLowerCase().contains("ext")

Bear in mind that you probably need to be a bit more clever than that though - what happens if you work with users who have emails like Dave.Nexte@yourplace.com ? (I'd reach for regular expressions and use "match" instead of "contains", but I'll leave that up to you)

Hi Nic,

Yes, I guess regular expresssion will be better option than simple string "contains" check. I have written a comment_if_ext.vm in ..templates/email/text/includes directory. which has contents like,

##Address is $recipient.getEmail()
#if($stringUtils.endsWithIgnoreCase($recipient.getEmail(), "mycomp.com"))
#if($stringUtils.endsWithIgnoreCase($recipient.getEmail(), ".ext@mycomp.com"))
#comment()
#visibility()
#else
#if($comment)
## Sending notification to internal users
Retrieve comment by using URL from summary below.
#end
#end
#else
#comment()
#visibility()
#end

I am parsing this in other .vm files like issueCommented.vm by adding this comment in the script.

#parse("templates/email/text/includes/comment_if_ext.vm")

But This simple logic is not working, is there anything else I need to do inorder to execute it? Is there some other dependency I dont know of.

PS: I have changed velocimacro.library.autoreload=false-->true so that i dont have to restart JIRA to reload the scripts.

Thanks,

Kalyani

Just adding some up to date information, as google likes this thread very much, when searching for jira template recipient. In Jira 6.3.6 the function to get the recipient's emailaddress is $recipient.getEmailAddress().

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

24,905 views 2 7
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you