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.
×I have the code below in my configuration section of my post function.
The mail.setFrom and mail.setFromName both work but the mail.setBcc doesn't.
Its worked with a string directly into this function but doesn't like when I pass a variable
mail.setFrom("email@domain")
mail.setFromName("ABC Mailbox")
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.component.ComponentAccessor;
def customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
def RECIPIENTSCF = customFieldManager.getCustomFieldObjectByName("Recipients")
def String RECIPIENTSBCC = RECIPIENTSCF.toString()
mail.setBcc(RECIPIENTSBCC)
return true
Hello
Since you wrote Its worked with a string directly into this function but doesn't like when I pass a variable , probably your variable RECIPIENTSBCC has incorrect format
Have you tested what exactly your variable RECIPIENTSBCC returns ?
See this article https://community.atlassian.com/t5/Jira-questions/Add-Bcc-to-custom-email-via-post-function/qaq-p/626373
The article listed (I've seen this before) shows the string entered directly.
As this is all contained in the configuration section, there is no output there so I passed it using the config mappings to the email template so I could print the contents and also get the type. It confirmed it was a string class
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think something is wrong with this string
def String RECIPIENTSBCC = RECIPIENTSCF.toString()
I created small script in console and it works, try it.
import com.atlassian.mail.Email;
import com.atlassian.mail.server.MailServerManager;
import com.atlassian.mail.server.SMTPMailServer;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.mail.Email;
import com.atlassian.mail.server.MailServerManager;
import com.atlassian.mail.server.SMTPMailServer;
MailServerManager mailServerManager = ComponentAccessor.getMailServerManager()
SMTPMailServer mailServer = mailServerManager.getDefaultSMTPMailServer();
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
String currentUserEmail = currentUser.getEmailAddress();
String cu = currentUser.getName();
String cuMail = cu+'@gmail.com';
Email email = new Email(currentUserEmail); //address TO
email.setSubject('some subject');
email.setMimeType("text/html")
email.setBody('some body');
email.setBcc(cuMail) //address BCC - gmail
mailServer.send(email);
email was sent to "currentUserEmail" and "cuMail" addresses
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.