Sending Multiple Attachments

Whilst working on a project today my team and I were trying to take attachments, from a list item in SharePoint, and then send them to a recipient as part of an email. We needed to cater for the possibility of several attachments being sent on a single email, and so we set about doing this.

We actually saw some strange messages when we were trying to send our attachments including:
 "Status code 400 and message": "No input parameters provided. Please provide required input parameters 'To', 'Subject' and 'Body'.\r\nclientRequestId:"


Alternatively I also saw the error where it said that it was unable to read the attachment content, which considering I was using the content dynamic content, I was really surprised.




There is a really simple solution to this, issue, but before I go into the solution I'm going to refer you to the blog post that we started with. This is a really good blog post by Sunay Vaishnav which was  "Advanced | Flow of the Week: Send multiple attachments on a single email".

There were a few people in the comments who had reported the exact same issue, and there were some solutions offered. In this I would like to suggest a simpler answer, and an explanation as to why I believe the error occurs.

The Issue

The issue purely comes down to the format in which the attachment content gets fed into the REST call being made to Outlook. Behind the scenes, all actions are web services calls which are made up of a URL, headers, and a body. The body and headers are both JSON, so if something goes in there which does not conform to the required schema, or even to valid JSON, then the action will fail.

Failure is exactly what we have seen with this action, with the direct input from the attachment content dynamic content resulting in poorly formed JSON. Effectively it's destroying the JSON so that not even the subject, to or anything else are recognisable.

The Resolution

The resolution is actually very simple, all it requires is a small expression. The content from the attachment is retrieved as a byte array, which won't be recognised as valid. What it actually wants is a base64 string. It is really easy to do that conversion as there is an expression named "base64", therefore we just need to wrap the attachment output in this expression.

To do this, append to your array variable in exactly the same way as was described by Sunnay, however when you put in your ContentBytes content, switch to the expression editor, and enter:

base64(<your attachment content dynamic content>) e.g. base64(body('Get_attachment_content'))


This will convert your content from byte to base64 so that the Outlook connector can then take the input and process it in the correct way. This will then cure your error and send the email attachments as you would expect.

If you need any further help on this, please feel free to ask.

Comments

  1. I was having a similar problem with the Azure DevOps attachment action - I’ll have to test if this fixes that as well.

    ReplyDelete
  2. A tie is calculated when each the Player and the Banker have the precise total number. This is when the 카지노 Player holds a higher card worth and is declared the winner. Legend has it that its origin dates again to 14th century Italy.

    ReplyDelete

Post a Comment