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

Outlook AppleScript:无需保存附件,复制邮件附件到新邮件并发送的问题

问题分析与修复方案

你的代码主要有两个核心问题导致附件无法添加:

  1. 未定义变量:forwardsubject和forwardemailaddress没有赋值,会导致脚本执行出错(即便你实际运行时补全了这两个值,也需要明确处理)
  2. 附件引用错误:你试图用附件的名称(name of thisatt)创建新附件,但Outlook的make new attachment需要的是文件的完整路径对象,而非单纯文件名。直接引用原附件的file属性即可,无需提取文件名。

修复后的完整代码:

tell application "Microsoft Outlook"
    -- 获取当前选中的邮件
    set theMessage to first item of (get current messages)
    set attFiles to attachments of theMessage
    
    -- 定义收件人地址和邮件主题(替换为你实际需要的地址,也可从原邮件提取)
    set forwardemailaddress to "recipient@example.com"
    set forwardsubject to "Fwd: " & subject of theMessage
    
    -- 创建新的外发邮件
    set newMessage to make new outgoing message with properties {subject:forwardsubject, content:content of theMessage}
    make new recipient at newMessage with properties {email address:{address:forwardemailaddress}}
    
    -- 复制原邮件的所有附件
    repeat with thisatt in attFiles
        -- 直接引用原附件的file属性,避免路径匹配问题
        make new attachment with properties {file:file of thisatt} at the end of newMessage
    end repeat
    
    -- 发送邮件
    send newMessage
end tell

关键修改说明:

  • 补充forwardemailaddress和forwardsubject的赋值,确保脚本可正常执行
  • 替换附件添加逻辑:从file:fname改为file:file of thisatt,直接复用原附件的文件引用,无需手动处理路径
  • 简化正文获取:直接使用原邮件的content,如果需要保留转发格式的正文,可保留你原有的fwdMessage逻辑,将forwardbody赋值给新邮件的content即可

注:如果原邮件包含内嵌图片等非文件型附件,可能需要额外处理,但普通文件附件均可通过上述代码正常复制。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 22:35:22