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

如何从Databricks调用Logic App发送邮件:传递用户ID、主题及附件

借助Azure Logic App从Databricks发送邮件的实现方案

完全可以实现你的需求:通过Databricks调用Azure Logic App发送邮件,同时传递用户邮箱(对应你提到的用户ID)、邮件主题,以及来自Azure Blob存储的附件。以下是具体实现步骤:

一、配置Azure Logic App

  • 创建一个HTTP触发的Logic App,定义请求体的JSON Schema,包含核心字段:
    {
      "type": "object",
      "properties": {
        "userEmail": {"type": "string"},
        "emailSubject": {"type": "string"},
        "blobAttachmentPath": {"type": "string"}
      },
      "required": ["userEmail", "emailSubject", "blobAttachmentPath"]
    }
    
  • 添加Azure Blob存储连接器:根据传入的blobAttachmentPath(格式为容器名/文件路径),配置获取Blob文件内容的操作。
  • 添加邮件发送连接器(如Office 365 Outlook、Outlook.com):将传入的userEmail设为收件人,emailSubject设为邮件主题,再把Blob存储获取的文件添加为附件。
  • 保存Logic App后,复制触发器的HTTP端点URL,用于后续Databricks调用。

二、Databricks端调用Logic App

在Databricks Notebook中,通过Python发送HTTP POST请求传递参数,示例代码如下:

import requests
import json

# 替换为你的Logic App触发端点URL
logic_app_endpoint = "https://prod-xx.westus.logic.azure.com:443/workflows/xxx/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=xxx"

# 可从你的用户列表、Blob存储中动态生成这些参数
email_payload = {
    "userEmail": "user@example.com",
    "emailSubject": "Databricks数据报表",
    "blobAttachmentPath": "data-container/monthly-report.csv"
}

# 发送请求
response = requests.post(
    logic_app_endpoint,
    headers={"Content-Type": "application/json"},
    data=json.dumps(email_payload)
)

# 验证请求结果
if response.status_code in [200, 202]:
    print("邮件请求已成功提交至Logic App")
else:
    print(f"请求失败,状态码: {response.status_code},详情: {response.text}")

三、关键注意事项

  • 为Logic App的HTTP触发器配置权限:可启用Azure AD认证或添加API密钥,防止未授权调用。
  • 给Logic App的服务主体分配Blob存储容器的读取权限,确保能正常获取附件文件。
  • 若需批量发送给多个用户,可在Databricks中遍历用户列表逐个调用,或在Logic App中添加循环逻辑批量处理。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 11:20:34