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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Can we have multiple "To recipients" in jira custom email handler code?

I would like to understand if we could use multiple To addresses in jira custom email handler.

I'm reading a CSV file and sending email to certain recipients if the conditions in other columns are met.

I could send email to one recipient but when I use multiple "To addresses", separated by comma, I get invalid email address error.

 

Below is my email handler function. Please help me out here.

def sendEmail(String emailAddr, String subject, String body) {
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()
if (mailServer) {
Email email = new Email(emailAddr)
email.setMimeType("text/html")
email.setSubject(subject)
email.setBody(body)
mailServer.send(email)

}

 

1 answer

1 accepted

2 votes
Answer accepted

Hi @Manjupriya 

You could try to use this code for multiple recipients 

import com.atlassian.mail.queue.SingleMailQueueItem
void
 sendEmail(String subjectString body, List<String> emailTo) {    
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer();    
if (mailServer) {        
Email email = new Email(String.join(",",emailTo))        
email.setSubject(subject)
        
email.setBody(body)
        
email.setMimeType(
"text/html")        
def item = new SingleMailQueueItem(email)        
ComponentAccessor.getMailQueue().addItem(item)    
}
}

@Vladislav Bykouski 

This worked for me.

Thanks a lot. 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Software

Presenting the "Best of 2020" Jira Software roundup!

Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...

7,018 views 8 28
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you