Skip to main content
June 8, 2026
Solved

MS Graph: Send email with attachment

  • June 8, 2026
  • 3 replies
  • 0 views

We are trying to send emails with attachments using the MS Graph sendMail API.

We're seeing an issue where the document is not being converted to Base64, see screenshot below.

Is the issue that we're starting with a json and converting to dictionary? This was done because if we define the dictionary directly, the key "@odata.type" is not recognised properly because of the period.

Thanks!

    Best answer by jesush905075

    Use the following code in your "attachments" attribute

    "attachments": {
          if(
            a!isNullOrEmpty(ri!attached),
            {},
            a!forEach(
              items: ri!attached,
              expression: {
                "@odata.type": "#microsoft.graph.fileAttachment",
                "name": concat(
                  document(fv!item, "name"),
                  ".",
                  document(fv!item, "extension")
                ),
                "contentType": concat(
                  "application/",
                  document(fv!item, "extension")
                ),
                "contentBytes": fv!item
              }
            )
          )
        }

    3 replies

    June 8, 2026

    Use the following code in your "attachments" attribute

    "attachments": {
          if(
            a!isNullOrEmpty(ri!attached),
            {},
            a!forEach(
              items: ri!attached,
              expression: {
                "@odata.type": "#microsoft.graph.fileAttachment",
                "name": concat(
                  document(fv!item, "name"),
                  ".",
                  document(fv!item, "extension")
                ),
                "contentType": concat(
                  "application/",
                  document(fv!item, "extension")
                ),
                "contentBytes": fv!item
              }
            )
          )
        }

    June 8, 2026

    Amazing that worked with one small change, line 18 should be  "contentBytes": toDocument(fv!item)

    Thank you v much!

    stefanhelzle0001
    June 9, 2026

    You tried to create a JSON string using text operations. Then the reference to the document turns into "[Document:xx]". Now, you try to turn this into a dictionary. How should Appian know what you are referring to?