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

Logic App提取AppId并分组至邮件正文的实现方案咨询

解决多次邮件发送+提取appId最后段的方案

核心思路

先批量提取所有appId的最后段内容,整理成统一的项目符号列表,只调用一次邮件发送接口,避免在循环内触发发送导致多次邮件。

步骤实现(以Python为例)

1. 解析JSON并提取目标内容

遍历JSON中的每个appId字段,通过字符串分割取最后一段,按需处理首字母大写:

import json

# 示例JSON数据
json_str = '''
{
  "apps": [
    {"appId": "com.google.ios.youtube"},
    {"appId": "com.apple.mobilesafari"},
    {"appId": "com.tencent.mm"}
  ]
}
'''

# 解析JSON
app_data = json.loads(json_str)
app_names = []

for item in app_data["apps"]:
    # 分割appId,取最后一段并首字母大写
    last_segment = item["appId"].split(".")[-1].capitalize()
    app_names.append(last_segment)

2. 生成带项目符号的邮件内容

把提取到的所有名称整理成符合要求的列表文本:

# 构建邮件内容
email_body = "提取的应用名称列表:\n\n"
for name in app_names:
    email_body += f"- {name}\n"

3. 一次性发送邮件

将整理好的内容作为邮件正文,仅调用一次发送函数:

import smtplib
from email.mime.text import MIMEText

def send_single_email(content):
    # 配置邮件参数(替换为你的实际信息)
    sender_addr = "your_sender@example.com"
    receiver_addr = "your_receiver@example.com"
    smtp_host = "smtp.example.com"
    smtp_port = 587
    email_password = "your_email_password"

    # 构造邮件
    msg = MIMEText(content, "plain", "utf-8")
    msg["From"] = sender_addr
    msg["To"] = receiver_addr
    msg["Subject"] = "应用名称提取结果"

    # 发送邮件(仅执行一次)
    with smtplib.SMTP(smtp_host, smtp_port) as server:
        server.starttls()
        server.login(sender_addr, email_password)
        server.send_message(msg)

# 触发单次发送
send_single_email(email_body)

关键注意事项

  • 绝对不要在遍历appId的循环内调用邮件发送函数,这是导致多次发送的根本原因
  • 如果你的JSON结构不同(比如appId在嵌套层级里),只需调整遍历的路径即可,核心逻辑不变
  • 若不需要首字母大写,直接去掉.capitalize()即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 12:25:22