In the scenario when we have a logic app with O365 Trigger - when a new email arrives, and the email comes with multiple attachments; there is a current limitation in Send Grid connector -Send Email V4; where we cannot use the attachments array to send the received attachments all at once in one email.
The below logic app shows the limitation scenario:
If we used the above structure, the send grid action will fail with the below error:
}
The reason the action fails; is due to the direct mapping from the O365 attachment array to the send grid attachments array; which has a difference in parameter names; such as Content.
For Send Grid Connector - Send email (V4); we can manually add the attachments using the individual attachment form; as below:
But this will cause each attachment to be sent in a separate email (due to the for each); which is not the desired target of the logic app.
By looking into code view, of the attachment array structure; when adding the attachment manually; we find it to be in the below structure:
Note: The attachment content from the dynamic content is "@{base64ToString(items('For_each')?['contentBytes'])}"; using it like this causes the send grid action to fail with error:
Also, the For Each parallelism need to be set to 1; in order to avoid incorrect variable assignments.
After having the array ready, we can pass it directly to the send grid action as below:
Below is the Full Logic App structure:
By this, we can send all received attachment (from the O365) to the Send Grid action; in one execution.