Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Scriptrunner Send Custom Email JIRA Service Desk Cloud

pontest
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 12, 2018

Hello,

I was wondering if it' possible to create a post function to send an email notification to a recipient specified in a custom field, could be free text, label field etc.

I've done something similar in Jira Server (Which was so easy to code in) but wanted to replicate this over to the cloud (as a business decision to migrate over) and wasn't able to find anything but the following:

def resp = post("/rest/api/2/issue/${issueKey}/notify")
.header("Content-Type", "application/json")
.body([
subject: 'Mail title',
textBody: "Body",
htmlBody: "<p>Body</p>",
to: [
users: [[
name: "username",
active: true
]]
groups: [[
name: 'some group'
]]
]
])
.asString()

I was sure how the string email address value can be added to the to key and also wondered if 'cc' would also work?

Any suggestion or guidance would be a great help thank you.

I'd really want to avoid webhooks for now

Many thanks!

 

 

1 answer

0 votes
Ismael Jimoh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 12, 2018

I’ve also not tried this on cloud but I think you can use a get to fetch email of the user first and then for cc, if more than one user, hashset the user’s email addresses and for loop to parse this as a string separated by commas to the to field.

Pon
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 12, 2018

Yes, so ideally, im going to do a GET request to retrieve the email address from a custom field and then use this in the POST request, but i wasn't sure how this can be done placing this value into the 'To' field above?

Something like this?


to: [
users: [[
name: "test@email.com"
]]

]

let alone i also have another field for CC which im not sure where to place this in the request body aswell.

Many thanks!

Tomas Arguinzones Yahoo
Contributor
March 6, 2019

Hi Pon, did you figure this out? I need to do the exact same thing where I need to notify an specific email address, like example@mydomain.com  and I havent been able to do it.

Can you please assist?

Thank you

Hemant November 25, 2021

hi @pontest @Tomas Arguinzones Yahoo were you able to figure this out?

Lukasz Grobelny
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 26, 2022

Working code:

def resp = post("/rest/api/2/issue/ts-1/notify")
.header("Content-Type", "application/json")
.body([
subject: 'Mail title',
textBody: "Title",
htmlBody: "<p>Email</p>",
to: [
// assignee: true,
users: [[
accountId:"User's ID",
active: true
]]
]
]).asString()
Lukasz Grobelny
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 13, 2022

@Hemant if you still need it my solutions should work :) 

Ricardo Martinez
Contributor
August 31, 2022

@Lukasz Grobelny 

Is there a way to send a custom email instead of a Notification?

Lukasz Grobelny
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 2, 2022

TBH I don't remember @Ricardo Martinez but if you want, I can check

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events