Logic Apps: Wrong attachments (binary files) in sending email from SharePoint list

Sener Gazi 55 Reputation points
2023-06-03T11:32:23.0333333+00:00

I built a workflow in Azure Logic Apps to send an email with attachments from a SharePoint list when a new item is created.

I used this tutorial and followed all the steps: https://powerautomate.microsoft.com/de-at/blog/multiple-attachments-single-email/

So far it works to send an email to a recipient. It also includes attachments but not the right format files. They are all binary files with this naming: ATT00001.bin, ATT00002.bin, ATT00003.bin and so on (all files have the same size).

Anyone that can help? Thank you in advance.

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,551 questions
{count} votes

Accepted answer
  1. Sonny Gillissen 3,751 Reputation points Volunteer Moderator
    2023-06-06T08:07:37.4366667+00:00

    Hi Sener Gazi

    Thanks for reaching out on Microsoft Q&A!

    The reason your attachment isn't added as expected is due to the fact binaries in Logic Apps are decoded in a JSON format. Therefor your binary isn't just BASE64, but looks somewhat like below:

    {
    "$content": "dGVzdA==",
    "$content-type": "text/plain"
    }
    

    Also see a sample from my Logic App test lab as well:User's image

    So to get to your BASE64 that needs to be added in the 'ContentBytes' part of the attachments you should not refer to the attachment contents from the selection menu, but point to the '$content' using the code below:

    body('Get_attachment_content')['$content']

    Next to that you're now also able to add a 'ContentType' part to the attachment object using:

    body('Get_attachment_content')['$content-type']

    Your object will then look somewhat like below:

    {
    "Name": "@{items('For_each_2')?['DisplayName']}",
    "ContentBytes": "@{body('Get_attachment_content')['$content']}",
    "ContentType": "@{body('Get_attachment_content')['$content-type']}"
    }
    

    Resulting in this output:

    User's image

    Please let me know if my answer was helpful by clicking 'Accept answer'. Feel free to drop additional queries in the comments below!

    Kind regards,

    Sonny


2 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.