Fetch Email attachments using Microsoft Email adapter in Oracle Integration Cloud
In the article, we’ll show how to fetch the attachments from email and dump the attachments on the SFTP server.
To complete this article, we should have in place:
- MS email connection: If not created, use the post to create a connection with Microsoft outlook
- FTP connection: If not created, use the post to create a connection with FTP
Below is the end to end use case which is demonstrated in the article:
- Fetch the emails from MS outlook
- Extract the attachments from each and every email
- Dump all attachments on the SFTP server
Let’s go ahead and see how to achieve this
- Create a scheduled integration with name “GetAttachments“
- Drop the Microsoft Email adapter just below the scheduled activity. The configuration wizard will be opened. On the very first screen enter below information and click the Next button
- What do you want to call your endpoints: Enter the name of your choice let’s say “FetchEmails“
- Choose an operation “Get message of a folder” and simply click the Next button
- On the last page of the wizard, simply click the Done button
- Edit the “FetchEmails” mapper and hardcode the “Inbox” value in “folder_id” template parameter as we are fetching the email from “Inbox” only
- Drop the “For Each” activity just below the MS email adapter and configure the below options in the opened wizard of “For Each” activity
- Name: Enter the name of your choice, let’s say “LoopEmails“
- Repeating Element: Drop the “value” element of the $FetchEmails node
- Current Element Name: Enter the name of your choice, let’s say “CurrentEmail“
- Drop the Microsoft Email adapter again under For Each loop. The configuration wizard will be opened. On the very first screen enter below information and click the Next button
- What do you want to call your endpoints: Enter the name of your choice let’s say “FetchAttachments”
- Choose an operation “Get an attachment collection” and simply click the Next button.
- Edit the “FetchAttachments” mapper and drop the “id” element under the “$CurrentEmail” node to the “message_id” template parameter
- Drop the “For Each” activity just below the MS email adapter again and configure the below options in the opened wizard of “For Each” activity. This loop will be used to loop over the attachments of each and every email
- Name: Enter the name of your choice, let’s say “LoopAttachments“
- Repeating Element: Drop the “value” element of the $FetchAttachments node
- Current Element Name: Enter the name of your choice, let’s say “CurrentAttachment“
- Now, drop the FTP adapter inside the inner “For Each” loop. The configuration wizard will be opened. On the very first screen enter below information and click the Next button
- What do you want to call your endpoints: Enter the name of your choice let’s say “WriteAttachment”
- On the Next screen, enter the information as below and click on the Next button
- Select Operation: Write File
- Select a Transfer mode: ASCII
- Specify an Output Directory: Enter directory location where the attachments will be dumped. In our case it is “/home/opc/attachments“
- Specify a File pattern: Let’s say it is “abc.csv“
- Enable PGP security: No
- Select “No” from the Do you want to define a schema for this endpoint ? and click the Next button and finish the wizard
- Edit the “WriteAttachment” mapper and do below mapping:
- FileReference: Click on this element, drop the seeded function “decodeBase64ToReference” on this element and map the “ContentBytes” element of the “$CurrentAttachment” node
- $CurrentAttachment->Name —> OutboundFTPHeaderType->fileName
- Integration is completed now. Activate the integration. Before submitting the integration, open the outlook email box and see the emails and attachments of each and every email. In my case, we have two emails, one has two attachments and another is having a single attachment. In total, there are three attachments
- Let’s submit the integration. After completion of the integration, open the SFTP location and notice the three files should exist there
This is how attachments can be fetched from outlook Inbox and save it to the SFTP location.