CC mail in send custom email

I'm trying to modify the built in script "send to custom email to accept a addresses inserted into some customfield in Email CC.

how can this be done?

in this https://jamieechlin.atlassian.net/wiki/display/GRV/Post+Functions documentation he tells that i can add

Email email = newEmail("someuser@example.com") // Set the TO address, optionally CC and BCC

some more examle? someone has modified the default script ?

3 answers

1 accepted

I had a quick peek of the API here:

http://docs.atlassian.com/jira/latest/com/atlassian/jira/mail/Email.html

The below should give you what you're after:

Email(String to)
Constructor specifying only the recipient.
Email(String to, String cc, String bcc)
Constructor including cc and bcc addresses.

Are you familiar with how to pull values from a custom field to populate the CC field?

tnks

to modify the built in script i've to hack the library then? can't i add somewhere else the script?

tnks

to modify the built in script i've to hack the library then? can't i add somewhere else the script?

hmm ... it won't be as easy as changing a single line of code if you modify the built in script. You'd also need to create an input field for the CC line similar to how the TO input field exists, and who knows how you'd modify the behavior of the plug in with your changes. If you have some programming experience, I'd suggest creating a custom script. If you have none, .. well .. see if you can borrow a programmer. here's an example of a script that I use that sends emails to certain users when all tasks for a parent issue are done. Dissect and modify if you wish:

import org.apache.log4j.Category
import com.atlassian.jira.ComponentManager
import com.atlassian.mail.server.managers.OFBizMailServerManager
import com.atlassian.mail.server.SMTPMailServer
import com.atlassian.jira.mail.Email
import com.atlassian.mail.queue.SingleMailQueueItem
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys

log = Category.getInstance("com.onresolve.jira.groovy.TicketWatcher")
log.setLevel(org.apache.log4j.Level.WARN)
log.debug ("---- Ticket Watcher script running ----")

def sendEmail = true
issue.getParentObject().getSubTaskObjects().each { t ->
	log.debug ("Analyzing $t")
	if (!t.getStatusObject().getName().equals("Done")) { 
		sendEmail = false
		log.debug ("$t is still open.  Do not send email.")
	}
}

if (sendEmail) {
	// configure email
	def projectManager = issue.getProjectObject().getLead().emailAddress
	def baseURL = ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL)
	def issueURL = baseURL + "/browse/" + issue
	def parentURL = baseURL + "/browse/" + issue.getParentObject()
	log.debug ("address: $projectManager")	
	log.debug ("base URL: $baseURL")
	log.debug ("issue URL: $issueURL")
	log.debug ("parent URL: $parentURL")
	
	OFBizMailServerManager mailServerManager = componentManager.getMailServerManager()
	com.atlassian.mail.server.SMTPMailServer smtp = mailServerManager.getDefaultSMTPMailServer()
	Email email = new Email(projectManager)
	email.setFrom(smtp.getDefaultFrom())
	email.setSubject("Ticket ${issue.getParentObject()} Requires Review")
	email.setBody("The last open task (<a href=\"$issueURL\">$issue</a>) for ticket <a href=\"$parentURL\">${issue.getParentObject()}</a> was just closed.  Please review <a href=\"$parentURL\">${issue.getParentObject()}</a> to determine if it should also be closed.")
	email.setMimeType("text/html")

	// send email
	SingleMailQueueItem item = new SingleMailQueueItem(email)
	try {
		ComponentAccessor.getMailQueue().addItem(item);
	} catch (Exception e) {
		log.warn("ERROR SENDING TICKET WATCHER EMAIL", e);
	}
}
log.debug ("---- Ticket Watcher script ended ----")

i've duplicated the send email, and modified adding another fields.

the problem is that i need to rebuild the jar i suppose

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

850 views 2 9
Read article

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