Hi, @Asaf Yosovich. I found this 'Solved' question from another community member that I think may contain an example you can work with.
Check out the answer from Ivan Tovbin
Use Scriptrunner to send one email collating all issues assigned to user
Good luck,
-dave
To construct an URL in a groovy script, it's helpful to fetch the "BaseUrl" property for your instance.
This way you don't have to hard-code the URL and the script will work even if you migrate to a different environment.
import com.atlassian.jira.component.ComponentAccessor
def baseUrl = ComponentAccessor.applicationProperties.jiraBaseUrl
Depending on the context where you want this script to execute, I'm assuming you'll already have access to the "issue" object.
So you can construct the URL for the link back to the issue:
def issueUrl = baseUrl + '/browse/' + issue.key
To send an email, I generally use the SingleMailQueItem object and MailQueue component.
Something like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.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
Issue issue //assumes this is already provided by the script context
def baseUrl = ComponentAccessor.applicationProperties.jiraBaseUrl
def issueUrl = baseUrl + '/browse/' + issue.key
if (mailServer && !MailFactory.settings.sendingDisabled) {
Email email = new Email('recipientEmail')
email.from = mailServer.defaultFrom
email.subject = 'you email subject'
email.mimeType = "text/html"
email.body = """your email body including the <a href="$issueUrl">link to the issue</a>"""
try {
SingleMailQueueItem item = new SingleMailQueueItem(email)
ComponentAccessor.mailQueue.addItem(item)
log.info "Success: email has been added to the mail queue"
} catch (MailException e) {
log.error "Failed to send an email due to error: e.message"
}
} else {
log.warn "Cannot send email. Outgoing emails are currently disabled"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.