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

Manjupriya December 27, 2020

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
Vladislav Bykouski December 27, 2020

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)    
}
}
Manjupriya December 29, 2020

@Vladislav Bykouski 

This worked for me.

Thanks a lot. 

Suggest an answer

Log in or Sign up to answer