Add Bcc to custom email via post function

Hello, 

I currently have a script that sends an email with no issues:

import com.atlassian.mail.Email;
import com.atlassian.mail.server.MailServerManager;
import com.atlassian.mail.server.SMTPMailServer;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.component.ComponentAccessor;

MailServerManager mailServerManager = ComponentAccessor.getMailServerManager()
SMTPMailServer mailServer = mailServerManager.getDefaultSMTPMailServer()
String currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().displayName

String issue = "JTP-123"

String subject = "Reminder Notification ${issue}"
String emailAddr = "emailadderss"

String body = """<h1>REMINDER</h1>

<p>Hi ${currentUser},<br/><br/>

This is a reminder that ${issue} was last updated 5 business days ago.</p>
"""

if (mailServer) {
Email email = new Email(emailAddr);
email.setSubject(subject);
email.setMimeType("text/html")
email.setBody(body);
mailServer.send(email);
} else {
// Problem getting the mail server from JIRA configuration, log this error
}

What im trying to do is add Bcc to the email that is sending via postfunction.

I can see that there is a method to add the Bcc called setBcc from this Doc

I've attempted to place the following line into my code - email.setBcc and provide an email address but it keeps throwing an error saying that setBcc does not exist.  

Does this work? or is there another way to get around this?

Many thanks, 

Pon

1 answer

1 accepted

1 vote

I believe this is already possible. It's just not implemented into the UI and involves some simple code.

The paragraph underneath the Condition and Configuration block states the following:

You can pass additional variables to the body and subject template using the config map, and dynamically control recipients using the mail variable.

Basically, this means that you can add additional code that allows you to manipulate the recipients and the fashion in which they receive the mail. To add a recipient as a BCC, you can add a line of code similar to:

mail.setBcc("youremailhere@email.com")

It should go in the Condition and Configuration box: 

Screen Shot 2017-08-17 at 12.18.49 PM.png

Thank you so much! It worked!

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,296 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot