Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

how to send custom attachment from my directory in email

HeSameddin Karim pour June 5, 2022

hi

I want to send custom attachment in mail that not attached on issue

I make it on jira file directory in address (/sharedhome/data/attachment-test/447788) 

for example 447788 is atatchment id in this directory and file name is viop.pdf

my script for send email is below and work right in custom script:

 

import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer
import com.atlassian.jira.component.ComponentAccessor

def subject = "Insert text here for ${issue.key}"
def body = "Hi ${issue.assignee.displayName} \n\nNow that XXXXX has been released, please complete XXXXX for the following issue: https://XXXXXXX/${issue.key} - ${issue.summary}. \n\n"
def emailAddr = issue.getAssignee().getEmailAddress()

def sendEmail(String emailAddr, String subject, String body) {
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()
if (mailServer) {
Email email = new Email(emailAddr)
email.setSubject(subject)
email.setBody(body)
mailServer.send(email)

} else {
// log this error
}
}

sendEmail (emailAddr, subject, body)

 

please help me to add attachment in this script

thanks regard

0 answers

Suggest an answer

Log in or Sign up to answer