Sending email with attachment

Omprakash Thamsetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 24, 2015

How I can get the attachment file and send an email with attachment in send custom email script? looking for piece of code to find the attachment file and sending email with that file attachment. Currently send a custom email script working fine without attachment.  

 

 

 

 

4 answers

1 accepted

1 vote
Answer accepted
Omprakash Thamsetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 25, 2015

I found the way to get the file path and filename by following code. Looking to attach this file in email notification. I had used for email notification email.setFrom, email.setCc and email.setBody but did not see email.setAttachment to email. Is there any way to send file as an attachment in email notification.

 

AttachmentManager attachmentManager = componentManager.getAttachmentManager() pathManager = componentManager.getAttachmentPathManager() 
 
attachmentManager.getAttachments(issue).each { attachment ->     filePath = 
PathUtils.joinPaths(pathManager.attachmentPath, issue.projectObject.key, issue.key, attachment.id.toString())   
 
filename = PathUtils.joinPaths(pathManager.attachmentPath, issue.projectObject.key, issue.key, attachment.filename)       
atFile = new File(filename)             
 }
1 vote
Jonas Andersson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 24, 2015

This thread answers how to get an attachment using rest:

https://answers.atlassian.com/questions/224783

To send that attachment you need to package it in a format that the receiving email server can cope with. If using microsoft exchange as mailserver and Linux on the server side you would encode the attachment using uuencode. 

 

0 votes
Omprakash Thamsetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 25, 2015

I am looking a way to find out to send an email notification with an attachment for the issue using the groovy script.  I am able to find the path and filename for the issue but did not find any method or class for the email attachment. I can see email.setCc, setBody etc. but not some thing like setAttachment. How I can attach the file to email notification.

 

Any help on this much appreciate.

0 votes
Omprakash Thamsetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 24, 2015

Jonas,

Is there a way to write some groovy code in existing "sendEmailToCustomer.groovy" inbuilt one? Basically need to get the file and then send an attachment format in a email when there is state change. I have right now configured workflow post function and its sending email but need to add code for attachment if it is exist. Can you please let me know how we can achieve this?

Suggest an answer

Log in or Sign up to answer