Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,490
Community Members
 
Community Events
165
Community Groups

Email scriptrunner output/log as attachment or body

Hi,

 I created a script that tracks the status of epic/sub-task and closes the parent link/initiative based on their statuses. I wanted to email the log/output of the script either as an attachment or body, how do I go about doing this?

1 answer

0 votes

Here is some sample code for sending an email via the default jira mail system

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.mail.Email
import com.atlassian.mail.MailException
import com.atlassian.mail.MailFactory
import com.atlassian.mail.queue.SingleMailQueueItem
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer

MailServerManager mailServerManager = ComponentAccessor.mailServerManager
SMTPMailServer mailServer = mailServerManager.defaultSMTPMailServer

if (!mailServer) return "No mailServer found on this instance"
if (!MailFactory.settings.sendingDisabled) return "Can't send emails while Outgoing mail is disabled"

Email email = new Email('recipent1@example.com,recipient2@example.com')
email.setFrom(mailServer.defaultFrom)
email.subject = "your custom subject"
email.body = "your body, dump your logs in here"

email.mimeType = "text/plain" //or "text/html"

SingleMailQueueItem item = new SingleMailQueueItem(email)
ComponentAccessor.mailQueue.addItem(item)

Suggest an answer

Log in or Sign up to answer
TAGS

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