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

Unable to set Bcc for a Scriptrunner post function Edited

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

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

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
TAGS
Community showcase
Published in Jira Software

How to create Jira issus from Excel file?

When to use CSV importer When managing your processes in Jira, there are many occasions where you need to create a lot of tasks. Creating them one by one will cost you a lot of time and effort and i...

4,664 views 22 33
Read article

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