Unable to set Bcc for a Scriptrunner post function

Darren Campbell November 6, 2019

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









 

 

 

1 answer

0 votes
fjodors
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 6, 2019

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

Darren Campbell November 6, 2019

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

fjodors
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 6, 2019

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

Like Sara Lam likes this

Suggest an answer

Log in or Sign up to answer