You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Power Automate编码MIME邮件Base64调用Graph API失败排查

使用Power Automate + Graph API发送MIME邮件时Base64编码报错的解决方法

问题现象

尝试通过Power Automate调用Graph API发送MIME格式邮件,外部工具生成的Base64编码能正常发送,但用Power Automate自带的base64()函数编码后,始终抛出ErrorMimeContentInvalidBase64String错误,提示“Invalid base64 string for MIME content”。

流的结构:先通过Compose生成MIME字符串,分两个并行分支:

  • 分支1:用base64(outputs('Compose_MIMEType'))编码
  • 分支2:直接使用在线工具生成的编码
    两个分支后续都调用Outlook的Send an Http Request操作,编码字符串逐字符对比无差异,但分支1始终失败。

测试用MIME内容:

To: me@gmail.com
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--

错误信息:

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

核心原因

Power Automate中默认的字符串换行符是CRLF(\r\n),而Graph API要求MIME内容的换行符必须是LF(\n)。虽然在线工具和Power Automate生成的Base64字符串肉眼看起来一致,但底层编码时,CRLF和LF的字节值不同,导致编码后的Base64实际存在差异(仅字符显示相同),最终被Graph API判定为无效格式。

解决方案

在调用base64()函数前,先将MIME字符串中的CRLF替换为LF,具体步骤:

  1. 在Compose生成MIME字符串的操作后,添加一个新的Compose操作,使用以下表达式替换换行符:

    replace(outputs('Compose_MIMEType'), '\r\n', '\n')
    
  2. 对替换后的字符串调用base64()函数:

    base64(outputs('Compose_Replace_CRLF'))
    
  3. 将新生成的Base64编码传入Graph API的请求中即可正常发送。

验证说明

替换换行符后,Power Automate生成的Base64编码会和使用LF换行的在线工具生成的编码完全一致,符合Graph API对MIME内容的格式要求,从而避免报错。

内容的提问来源于stack exchange,提问作者Steven Bitaxi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 09:20:17