Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to send custom mail based on a custom field value via ScriptRunner

Steven Cruz March 13, 2019

We want to send an email to an email alias based on the value of a custom field "Pod", e.g. if Pod =="ABC" then send mail to "myusergroup1.test.com", if Pod="DEF" then send mail to "myusergroup2.test.com. We are using the cloud version of Jira.

 

Is there a similar example of this done via ScriptRunner?

1 answer

0 votes
Shreyance Shaw March 13, 2019

Hi Steven,

This is a script snippet on sending email from Groovy using JIRA SERVER, hopefully this would give you pointers to get it done for JIRA Cloud

try{ 
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()   
String emailAddr = "Email Address"    
String emailSubject = subject    
StringBuilder emailBody = new StringBuilder()    
emailBody
.append("Your email message")    
if(mailServer){
Email email = new Email(emailAddr);
email
.setSubject(emailSubject);
email
.setBody(emailBody.toString());
mailServer.send(email);
}
else{
throw new Exception("Could not find Mail server object from JIRA Mail Server Manager")
}
}

catch(Exception Ex){
log
.error("Could not send email")
log.error(Ex)
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events