Search code examples
microsoft-graph-apibase64power-automate

Base64 encoded MIME email fails


I'm trying to send email using Power Automate and the Graph API in MIME format. If I encode the email externally, it works fine but if I encode it using the encode64 function in Power Automate it throws and error invalid base 64 string for MIME content.

In the flow, there is an action containing the MIME string data, followed by two parallel branches. One Compose encodes the MIME data base64(outputs('Compose_MIMEType')) while the one in the parallel branch uses the already encoded string.

I used https://www.base64encode.org/ to encode it online in UTF-8 and LF (Unix) options. However I also tried it from https://base64.guru/converter/encode using "Base64 Standard = Main" and "Character Encoding = UTF-8" which resulted in a different Base64 encoded string that also worked fine.

Those are followed by two Outlook Send an Http Request actions which each respectively send the base64 encoded strings. Screenshot from Power Automate showing a compose action named Compose MIMEType, two parallel branches below it with a Compose action on the right showing Base64 encoded data followed by an Outlook Send an Http Request action, and the branch on the left has a Compose action that encodes the MIMEType content followed by another Outlook Send an Http Request action

There does not appear to be any difference between the two encoded strings after a character/character comparison but the action using the Power Automate encoded string fails.

Screenshot from Power Automate showing two parallel actions - Send Http Request to Outlook

Here is the test email I'm using

To: [email protected]
Subject: Concert!
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="frontier"

--frontier
Content-Type: text/plain

Hey Jane,
Let's go as a team next Friday.
Depeche Mode concert!

--frontier
Content-Type: text/html

<html>
<body>
<p>Hey Jane,</p>
<p>Let's go as a team!</p>
<p>Depeche Mode concert next Friday.</p>
</body>
</html>

--frontier--

Base64 Encoded via online

VG86IG1lQGdtYWlsLmNvbQpTdWJqZWN0OiBDb25jZXJ0IQpNSU1FLVZlcnNpb246IDEuMApDb250ZW50LVR5cGU6IG11bHRpcGFydC9hbHRlcm5hdGl2ZTsgYm91bmRhcnk9ImZyb250aWVyIgoKLS1mcm9udGllcgpDb250ZW50LVR5cGU6IHRleHQvcGxhaW4KCkhleSBKYW5lLApMZXQncyBnbyBhcyBhIHRlYW0gbmV4dCBGcmlkYXkuCkRlcGVjaGUgTW9kZSBjb25jZXJ0IQoKLS1mcm9udGllcgpDb250ZW50LVR5cGU6IHRleHQvaHRtbAoKPGh0bWw+Cjxib2R5Pgo8cD5IZXkgSmFuZSw8L3A+CjxwPkxldCdzIGdvIGFzIGEgdGVhbSE8L3A+CjxwPkRlcGVjaGUgTW9kZSBjb25jZXJ0IG5leHQgRnJpZGF5LjwvcD4KPC9ib2R5Pgo8L2h0bWw+CgotLWZyb250aWVyLS0=

Base64 encoded via Power Automate

VG86IG1lQGdtYWlsLmNvbQpTdWJqZWN0OiBDb25jZXJ0IQpNSU1FLVZlcnNpb246IDEuMApDb250ZW50LVR5cGU6IG11bHRpcGFydC9hbHRlcm5hdGl2ZTsgYm91bmRhcnk9ImZyb250aWVyIgoKLS1mcm9udGllcgpDb250ZW50LVR5cGU6IHRleHQvcGxhaW4KCkhleSBKYW5lLApMZXQncyBnbyBhcyBhIHRlYW0gbmV4dCBGcmlkYXkuCkRlcGVjaGUgTW9kZSBjb25jZXJ0IQoKLS1mcm9udGllcgpDb250ZW50LVR5cGU6IHRleHQvaHRtbAoKPGh0bWw+Cjxib2R5Pgo8cD5IZXkgSmFuZSw8L3A+CjxwPkxldCdzIGdvIGFzIGEgdGVhbSE8L3A+CjxwPkRlcGVjaGUgTW9kZSBjb25jZXJ0IG5leHQgRnJpZGF5LjwvcD4KPC9ib2R5Pgo8L2h0bWw+CgotLWZyb250aWVyLS0=

Error

{
  "error": {
    "code": "ErrorMimeContentInvalidBase64String",
    "message": "Invalid base64 string for MIME content."
  }
}

What am I missing? Is anyone else experiencing anything similar?


Solution

  • The solution would be to add a "string" function. So your base64 result should be in a string function. enter image description here

    enter image description here

    Erika