cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
chartergrowth
Frequent Visitor

Attaching Sharepoint Attachments to Email

Hello,

I am trying to attach a attachment from sharepoint to an email everytime a attachment is created or modified but the flow keeps failing at the email part.

 

Capture.PNGCapture1.PNG

I keep getting this error everytime the flow runs.

Capture3.PNG

What am I doing wrong? 

 

Thanks.

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @chartergrowth,

 

I think there is something wrong with the Compose action within your flow, the Attachment Content dynamic content and the DisplayName dynamic content should not be wrapped with double quotes.

 

I have made a test on my side and please take a try with the following workaround:

  • Add a "When an item is created or modified" trigger, specify Site Address and List Name.
  • Add a "Get attachments" action, specify Site Address and List name, Id field set to ID dynamic content of the trigger.
  • Add a Variables-> "Initialize variable" action, Name set to AttachmentArray, Type set to Array and Value set to empty.
  • Add a "Apply to each" action, input parameter set to output of "Get attachments" action.
  • Within "Apply to each" action, add a "Get attachment content" action, specify Site Address and List Name, Id field set to ID dynamic content of the trigger, File Identifier field set to Id dynamic content of the "Get attachments" action.

         Add a "Append to array variable" action, Name choose AttachmentArray, Value set to following json data formula:8.JPGWithin above json data, there are two elements. The key of first element set to Name and corresponding value set to DisplayName dynamic content. The key of second element set to ContentBytes and corresponding value set to following formula:

body('Get_attachment_content')?['$content']
  • Under "Apply to each" action, add a "Send an email" action, Attachments field set to AttachmentArray variable, Is HTML set to Yes.

Image reference:9.JPG

 

10.JPG

The flow works successfully as below:11.JPG

 

12.JPG

 

 

Best regards,

Kris

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

9 REPLIES 9
v-xida-msft
Community Support
Community Support

Hi @chartergrowth,

 

I think there is something wrong with the Compose action within your flow, the Attachment Content dynamic content and the DisplayName dynamic content should not be wrapped with double quotes.

 

I have made a test on my side and please take a try with the following workaround:

  • Add a "When an item is created or modified" trigger, specify Site Address and List Name.
  • Add a "Get attachments" action, specify Site Address and List name, Id field set to ID dynamic content of the trigger.
  • Add a Variables-> "Initialize variable" action, Name set to AttachmentArray, Type set to Array and Value set to empty.
  • Add a "Apply to each" action, input parameter set to output of "Get attachments" action.
  • Within "Apply to each" action, add a "Get attachment content" action, specify Site Address and List Name, Id field set to ID dynamic content of the trigger, File Identifier field set to Id dynamic content of the "Get attachments" action.

         Add a "Append to array variable" action, Name choose AttachmentArray, Value set to following json data formula:8.JPGWithin above json data, there are two elements. The key of first element set to Name and corresponding value set to DisplayName dynamic content. The key of second element set to ContentBytes and corresponding value set to following formula:

body('Get_attachment_content')?['$content']
  • Under "Apply to each" action, add a "Send an email" action, Attachments field set to AttachmentArray variable, Is HTML set to Yes.

Image reference:9.JPG

 

10.JPG

The flow works successfully as below:11.JPG

 

12.JPG

 

 

Best regards,

Kris

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Hi,

Thanks for you help. I had to make a couple of changes to what you posted above but it is now working!

 

Another quick thing. I tried adding a create file in Box action to my flow but it doesn't give me the option to add the variable content. I tried adding the function variable('AtachmentArray'). The flow runs and succeeds but the file that shows up in box says that the document type is not supported and when I download it, I just get a bunch of code. How can I get the variable attachment to work?

 

Thanks.

Hello,

 

I follow your instructions and the flow doesn't work. The flow checker asks me to enter a valid json while I put the same function as you.

 

Best regards,

Alexandre.

I found my mistake, I forgot the comma to the function json.

 

Thank you for your help,

Alexandre.

I've got a Flow set up if not exactly like yours Kris, it is very similar and it completes with an email being sent but I'm not seeing the attachments that are with the list item. Any thoughts on why this is happening? 

I can see the Attachments when looking at the Flow run with names like 

"[\n\"Name\" Travis Test Build - App List Template.xlsx\n\"ConentBytes\" UEsDBBQABgAIAAAAIQDh...... But they are not in the email.

 

I'm struggling to get this same thing to work on my Flow. I have a PowerApp set up to collect Employee Action Forms from my operations team. An HTML template and some replace() in a number of composes I've gotten it to create a PDF to send the form to HR. The sharepoint list does allow for attachments (appraisals and docs to accompany any promotion or increase) but I'm not able to get the additional documents to attach with the Action Form.

 

attachVar.jpg

I went thru the array variable but can't get it to end up attaching to the email. I'm running the Compose to union attachements from 2 different locations. Any help is appreciated:

 

PDFAttach: creates the object to later be in a CreateArray() in the union

GetEmailBody: Template HTML email file for the body of the email. Simplified message editing

Initialize the Variable:

Condition: If the Sharepoint list item has an attachement then it sends all attachements, if it doesn't is sends the original attachement.

Get Attachement:

Apply to each:

AttachUnion: The union() that combines the variables and the orginal attachment.

Email

 

Everything succeeds in the Flow but there is not attachment to the email when it comes across.

Sang_diep1309
Regular Visitor

Thank you for the instructions for creating the flow. 

 

I got the flow to succeed, but the attachment in the email is not readable. It just shows list of codes which is not the content of the original file attached in the Sharepoint list. Please help. Thanks

 

 

I have the same problem
If I attach one file it is fine
but If I attach array of more than one file, it is sent in the email but not readable

 

DanielRK
Continued Contributor
Continued Contributor

Hi Kris,

 

Thanks for explaining how to attach a SP list attachment to an email.

 

I did exactly as you have shown above and it works for when the trigger is Sharepoint "when an item is created". I want to have the Sharepoint Trigger "for a selected file" or the powerapps trigger.

 

However it doesn't work for the "for a selected file" trigger. I changed nothing else and I remapped the ID fields all the way through the flow to update this change.

 

I haven't tried the powerapps trigger yet.

 

Can you advise me if these trigger will work and what I need to do to get them working properly?

 

Thanks a lot.

 

Regards,

 

Daniel

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,420)