Email scriptrunner output/log as attachment or body

Joel Batac June 21, 2022

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
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 25, 2022

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