How do I add attachments to an e-mail with Automation for JIRA

andreas
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.
March 6, 2017

Is it possible to add attachments to an e-mail with Automation for JIRA ?

9 answers

1 accepted

13 votes
Answer accepted
andreas
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.
March 6, 2017

So you can't embed attachments directly in an e-mail (we don't support this due to the fact that attachments in JIRA could be far to large for emails), but you can add links using smart fields.

Here's an example rule:

Project automation - Code Barrel JIRA 2017-03-07 11-12-49.png

So this email body will iterate over all attachments on an issue and produce links that allow recipients to download the attachment directly from JIRA: 

Hi there,


Attachments:
<ul>
{{#issue.attachment}}
<li><a href="{{content}}">{{filename}}</a></li>
{{/issue.attachment}}
</ul>

Cheers,
  Auto
Susan Ostreicher
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.
October 19, 2017

Hello @andreas - can this code be adapted to add a comment (instead of an email) with links to all attachments?  Thanks!

Like # people like this
Jon Bartholomew March 26, 2019

Hi @andreas. We want to send the attachments to an external support user, but the link would require a JSD account. Is there any way around this now? Thanks.

Like # people like this
dharper April 9, 2019

Hi @andreas , really Automation for Jira has been great to work with. We are slowly learning how to optimize our JIRA instance. In light of this question, I am having trouble adding the attachment link to an email. The caveat is that Im using another plugin for creating additional attachment custom fields. 

Would you have a suggestion for how to deliver the link to the attachment in our custom field (customfield_17703). The reporter role would be the recipient of the email.

Any help would be greatly appreciated. 

Cheers

Like Ali Al Bimani likes this
Daniel Alonso July 19, 2019

Is there a way to do that with the Triggered Issue? I tried with this codes without luck any suggestions?


{{#triggerIssue.attachment}}
* [{{filename}}|{{content}}]
{{/}}


{{#triggerIssue.fields.attachment}}
* [{{filename}}|{{content}}]
{{/triggerIssue.fields.attachment}}

Richard Vencu October 14, 2020

So far I could not find a way to overcome the limitations to send the attachments to the external support user purely using Jira tools. Even exposing them to the portal is a bit tricky, they need to be inside a comment.

I ended up fashioning a PHP script to expose a REST endpoint that would ingest destination email list, the email body and the attachment details then compose and send such emails from the corporate email servers. In automation instead sending the email I am sending a request to that endpoint. 

The PHP script itself logs in to Jira instance with an admin token hence it has access to all attachments it needs.

Like # people like this
Boris Berenberg - Atlas Authority
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.
October 29, 2020

The alternative is to use an app like Notification Assistant for Jira which supports sending attachments up to 20 MB in size.

Gnana Sekhar Reddy November 14, 2022

Hi @andreas 

Is there any possibility to attach a particular attachment only in the email notification. Can you please confirm me once.

15 votes
Krishna Prasad March 17, 2022

@andreas / All  - Now that JIRA is allowing to download Email attachments directly from email notifications rather than logging into the portal, can you please hep advise how we can acheive the same via Automation - Send Email option please?

Reay appreciate all your support in this regard.

Regards,

Krishna

2 votes
Jude Botten
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 13, 2022

I still cannot work around that the link in question that is created from the smart values does not allow anyone other than admins to see the file. Is there a way we can open this to any customer or user in the tenant?

1 vote
SHADOW November 15, 2019

Hi, 

{{#issue.attachment}}<li><a href="{{content}}">{{filename}}</a></li>{{/issue.attachment}}

This code displays a list of all attachments, how to get only the file that is added now? for example, by the trigger for changing the attachment field - display a comment only with the attachment added.

David Israel April 5, 2020

{{#issue.attachment.last}}<li><a href="{{content}}">{{filename}}</a></li>{{/issue.attachment.last}}

Like Luciana Maria Gerhard likes this
Mark Hostetler June 10, 2020

Would this only pull down the only most recent file?

David Israel June 11, 2020

Yes, it returns the most recent array element.

Mathew Sommers September 9, 2020

David, when I use the .last it pulls the last attachment in the list rather than the most recently added to the list.  

Is there a way to get last by date?

Tnx
-Matt

Like Javier_Corchado likes this
David Israel September 10, 2020

Hi Matthew, when I used this, the attachments list (array) was populated internally chronologically, meaning the last one also was the most recent one. In case Atlassian has changed something there, you could also try '.first' instead of '.last'.

There is an ugly third possibility: If (like in the 'Approvers' array field) the order (index) of the attachments array elements keeps constantly changing, you would have to (only very quick summary) use the new automation feature (formerly Automation for Jira) to create a rule that

  • gets the total number of attachments (attachment.size)
  • iterates in a loop over each object id (attachment.get(0 to [whatever is attachment.size.minus(1)]) by creating fields in your issue that can be used as loop variables for
    • loop iteration
    • and array object index (this is tricky, because '.get(X)' requires a 'real' integer, and Jira number field data type is always floating point, so you'd need to e.g. use an auxiliary label field to be populated loop iteration by iteration with one additional element, then the 'auxiliary.size' property will return you a 'real' integer you can leverage for use in .get(x))
  • pull the 'attachment.get(x).created' properties for each element in attachments
  • save this somewhere together with the array index for a date comparison to decide what's newest (or in each loop iteration discard the previous iterated element when the current one is newer).

Hope that helps! 

Like # people like this
Chris Tetzlaff March 15, 2024

Shadow,  this solved our problem, thank you! 

1 vote
Susan Ostreicher
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.
June 7, 2018

For anyone else who comes across this... I had trouble with the code above, but this seemed to work for me: 

Attachments:
<a href="https://example.com/jira/secure/attachment/{{issue.fields.attachment.id}}/{{issue.fields.attachment.filename}}">{{issue.fields.attachment.filename}}</a>
AKSHAY THAKARE September 5, 2018

Hi, @Susan Ostreicher only administrator of Jira can access this link, so what about other users?

Like # people like this
0 votes
Benjamin Høegh August 12, 2024

Is there no way to attach a PDF to a email send from automation without adding it to the issue?


Levente Szabo _Midori_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
August 13, 2024

@Benjamin Høegh Have you tried Better PDF Automation (free)? It can do just that as a companion app for Better PDF Exporter and it's available for both deployment types.

0 votes
Andreas Denzler
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 4, 2023

Unfortunately still, the problem is not solved, that the accepted answer here only sends a link to a REST API endpoint in the email and users without (admin) account can not download the attachement.

Is there a solution for this by now?

0 votes
Stephan Häger
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 28, 2020

Hi, 

Use the lagacy automation. With the legacy automation you can also send the ticket description. In case the ticket description contains images etc, they are sent. 

Best regards

Stephan 

Deleted user June 28, 2021

Hi Stephan,

what about comments with attachements?

Like # people like this
0 votes
Susan Ostreicher
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.
October 5, 2018

Hi @AKSHAY THAKARE, I'm sorry for the slow reply. From what I can tell, anyone with permission to view the request (e.g. a reporter or a request participant) can access that link. Have you seen that's not the case? 

AKSHAY THAKARE April 2, 2019

Yeah, but in my case, this is not happening only admin can access that link even reporter also not able to view that attachment.

Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events