Save Outlook Attachment as SharePoint File or as DataVerse Email Attachment

This question has been going around on the power users community forums and I thought it would be nice to blog it because it is always gets tricky trying to save files from different data sources , so for this we have a single source the outlook connector and there is two destination.

  1. Sharepoint File
  2. Dataverse Email Attachment

Lets Get Started!

So the starting point is the Flow Trigger which is “When a new email arrives (v3)”

Then the next step is to get the Attachments from the Email by using the below steps:

  1. Loop on the attachments from the triggerOutputs
  2. Use Get Attachment (v2) to get each attachment

Then to save to sharepoint that was pretty easy .. Just using the outputs of the Get Attachments (V2) has worked from the first Go!

Name and Content Bytes!

What about dataverse?

So for DataVerse we are creating a new email activity and adding the attachments to it as below but it wasn’t straight forward adding the attachment.

Step 1: Easy : Create the Email Activity

Step2: Add the Attachment and here is a couple of tricks

  1. when you select the table name attachments there is 2 tables , make sure you select first one.
  2. Attachment(Attachments) just pass null from the Expressions Pane … Weird but how this is working.
  3. Entity: Do not select one of the available Options , just use enter a custom value and type email otherwise you will get an error.

The entity with a name = ‘4200’ with namemapping = ‘Logical’ was not found in the MetadataCache. MetadataCacheDetails: ProviderType=Dynamic, StandardCache=True, IsLoadedInStagedContext = False, Timestamp=3040485, MinActiveRowVersion=3040485, MetadataInstanceId=51707140, LastUpdated=2021-08-04 11:35:57.770

And when it came to setting the body ; it wasn’t as easy as passing the content bytes directly as with sharepoint ..

Attempt 1: Pass Content Bytes directly .. Error Received

The attachment body should be a valid Base 64 string

Attempt 2: Convert Content Bytes to base 64, No error received, file was attached but corrupted

Attempt 3: Binary ???!!! .. Weird but this is what worked for me run successfully and file was not corrupted.

Hope this is useful!

2 thoughts on “Save Outlook Attachment as SharePoint File or as DataVerse Email Attachment

  1. YOU ROCK!!! Thanks so much for this post!!! Spent a couple days trying to figure out why my attachments to Dataverse were corrupted. Using binary() was the answer.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with WordPress.com
Get started
%d bloggers like this: