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

PowerApps中使用Office365Outlook.SendEmail添加附件及嵌入手绘图片问题

解决Power Apps中Office365Outlook.SendEmail的附件与内嵌图片问题

一、附件控件传递问题解决

DataCardValue4作为附件控件,直接传递其值无法满足Office365Outlook.SendEmail的参数要求,需要遍历控件的Attachments属性,构造符合格式的附件数组:

Office365Outlook.SendEmail(
    "收件人邮箱地址",
    "邮件主题",
    "邮件正文内容",
    {
        Attachments: ForAll(
            DataCardValue4.Attachments,
            {
                Name: DisplayName,
                ContentBytes: Value,
                ContentType: '@odata.type'
            }
        )
    }
)
  • ForAll遍历附件控件中的每个文件,提取文件名(DisplayName)、字节流(Value)和类型(@odata.type),生成函数可识别的附件结构。

二、PenInput图片嵌入邮件正文解决

PenInput返回的Blob字符串需要截取Base64编码部分,再通过HTML正文+内嵌附件的方式实现图片嵌入,同时整合其他控件内容:

// 提取PenInput图片的Base64编码部分
Set(
    penImageBase64,
    Mid(PenInput1.Image, Find(",", PenInput1.Image) + 1)
);

// 发送整合后的邮件
Office365Outlook.SendEmail(
    "收件人邮箱地址",
    "邮件主题:" & Input_Summary.Text,
    "<html>
        <body>
            <p>姓名:" & Input_Name.Text & "</p>
            <p>日期:" & Text(DatePicker1.SelectedDate, "yyyy/mm/dd") & "</p>
            <p>摘要:" & Input_Summary.Text & "</p>
            <p>手写签名:<img src='cid:penSignature' style='max-width:300px;' /></p>
        </body>
    </html>",
    {
        IsHtml: true,
        Attachments: [
            // 内嵌手写签名图片
            {
                Name: "penSignature.png",
                ContentBytes: penImageBase64,
                ContentType: "image/png",
                IsInline: true
            },
            // 追加附件控件中的文件
            ForAll(
                DataCardValue4.Attachments,
                {
                    Name: DisplayName,
                    ContentBytes: Value,
                    ContentType: '@odata.type'
                }
            )
        ]
    }
)
  • 用Mid和Find截取Blob字符串中逗号后的纯Base64编码内容;
  • 邮件正文启用HTML格式(IsHtml: true),通过cid:penSignature引用内嵌附件,其中cid值需和附件的Name一致;
  • 内嵌附件需设置IsInline: true,确保图片显示在正文而非普通附件列表中。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 18:04:55