In modern workflows, automating email attachment retrieval is a common requirement, but traditional methods like IMAP (Internet Message Access Protocol) and POP3 (Post Office Protocol) may not always be viable due to company or security policies. In this customer use case, Principal Technical Consultant, Richard Auger explores an alternative approach: leveraging REST API to download Office 365 email attachments and process them efficiently.
By using REST API, we can query the mailbox, identify emails with attachments, and selectively download the necessary files - all while ensuring that attachments are removed after retrieval to prevent duplicate downloads. This guide walks through the step-by-step process, utilising the GoAnywhere OAuth cloud connector.
How can you automate file transfers from email without IMAP or POP?
One of our secure file transfer customers recently approached us with an interesting use case: they needed to download email attachments from Office 365 and send them into a workflow, without using IMAP or POP3 due to company policy.
The solution? Use a REST API to interrogate the mailbox for emails, then use a REST API again to check the emails attachments. Finally, use the REST API to download the attachment and delete it from the email (to avoid downloading it a second time).
To do this, you'll need two resources:
-
A REST server with a URL of https://graph.microsoft.com/v1.0/
-
The free GoAnywhere OAuth cloud connector, completed with your client and tenant IDs
So where to start?
When working with REST API you will need to read JSON responses. So to start you need to create a workspace to save the JSON files.
You then need to create a token that will be used to authenticate in the REST calls. For this, you can use the GoAnywhere OAuth cloud connector, which produces a variable containing the token.
You can go straight to the first REST Get command. The Uniform Resource Identifier (URI) that we will use (which simply gets appended to the REST server URL) is:
users/mailbox_name/mailfolders/inbox/messages |
The resulting JSON is then read in. However, really you are only interested in the columns ‘/value/id’ and ‘/value/hasAttachments’. This is going to give you a rowset, which you can then loop through.
Check the content of the ‘hasAttachments’ field. If it is set to true, the email contains attachments. You can then run another REST GET request against the particular email, using the URI.
users/mailbox_name/messages/${item[2]}/attachments |
Here, ${item[2]} represents the email ID. This gives you a new JSON containing a list of attachments to read into a new rowset. Loop through this new rowset and check the name of each attachment. If it ends with ‘.xml’, then issue a final REST GET with a new URI:
users/mailbox_name/messages/${item[2]}/attachments/${item1[1]}/$value |
In this request, ${item1[1]} is the ID of the individual attachment and the $value is a special parameter which indicates to get the content for the attachment. This REST GET can save the file into whatever location is applicable.
Finally, issue a REST DELETE against the file to avoid downloading it twice:
users/mailbox_name/messages/${item[2]}/attachments/${item1[1]} |
By following this step-by-step approach, you can effectively automate the retrieval and processing of Office 365 email attachments with REST API instead of using IMAP or POP3. To help visualise the entire workflow, here’s a screenshot of the project outline, summarising the steps we've covered above.
If you need further assistance or support with your own MFT workflows, Pro2col is the leading UK file transfer consultancy. We offer a range of services, including consultancy, managed services, training, and hosting. Get in touch with us to see how we can help you optimise your file transfer and automation processes. Whether you're looking for expert advice or full-scale project support, we’re here to help.
About the Author |
|
![]()
|
Richard Auger is the Principal Technical Consultant at Pro2col, and has been working in the field of file transfer and middleware for around twenty years. He’s currently Pro2col’s lead Technical Consultant helping clients get the most out of their MFT solution. One of the reasons why Richard loves tech is his curious nature. Tech is constantly evolving, so he is always trying the latest tech releases and testing their limits. |


Further Reading:
