How to get the attachment of an attached email with Power Automate
- Matthias Schmitz
- Mar 24
- 2 min read
To get the attachment that is attached to an attached email you can use the following Power Automate flow.
Important to mention is that I wanted to demonstrate a basic version of this flow. It can be extended in various way. Covering .zip files, even more nested attachments and so on. I assume that you have a basic knowledge of Power Automate and will not describe all steps in detail.
Let's start with the example of having two emails that were sent to our inbox:
Email 1 with an attachment:

Email 2 with an attachment and email 1 as an additional attachment:

Now, we want to get all the attachment of the emails.
If we tried to use the "normal" way we would get only one attachment: the pdf file.


This is a limitation of the Outlook connector. We do not get any email files just the normal file types such as .xlsx, .docx and so on.
What we need to use to get our email and also the attached file is a http post to the graph api.
This could look as follows:

This will give us all the attachments of the email that came into our inbox.
Now we can retrieve the dynamic data with the Parse JSON action and loop through each attachment. Important here is to pay attention to the @odata.type.
'#microsoft.graph.itemAttachment' or '#microsoft.graph.fileAttachment'
In this post we will only cover the itemAttachment since this is the attached email which has the pdf file that we want. The fileAttachment is the pdf file that we saw in the email before.

With another HTTP request we can now get the attachments of the attachment:

In the next step we can loop through the attachments of the attachment to get the contentBytes and the name of the file.

Looped output: body('Send_an_HTTP_request_to_get_attachments_of_email_attachment')?['item']?['attachments']
Get contentBytes: items('Apply_to_each_attachment_of_email_attachment')?['contentBytes']
Get name: items('Apply_to_each_attachment_of_email_attachment')?['name']
Summary:
This is one way I found to get the attachments of an attached email. We use a similar version in a project.
However, the explained version is not final. You need to take care of nested attachments. There could be emails that are attached in email that are attached in emails.
You also need to take care of a limit. I suggest to go with a limit of three nested items. Otherwise, it could be used for bad purposes.
I also recommend to use child flows her to write all of the the nested item checks all over again.
Let me know what you think and if you solved this topic in a different way.
Comments