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

Mac版Mail如何设置关联日历事件触发自动回复的邮件规则

方案选型结论

AppleScript是该需求的最优实现方案,无第三方依赖,系统级兼容稳定性高:

  • Mac端Mail原生支持收信规则触发AppleScript动作,不需要额外开发常驻后台进程
  • AppleScript原生支持调用通讯录、日历的系统接口,除系统权限申请外不需要额外适配
  • 资源占用极低,不会产生额外的后台性能开销
具体实现步骤

1. 编写并部署AppleScript脚本

打开系统自带的「脚本编辑器」应用,新建文稿,粘贴以下代码,根据自身需求修改开头配置项的参数:

using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        -- ========== 配置项 按需修改 ==========
        set targetContactGroupName to "工作联系人" -- 替换为通讯录内指定的联系人群组名称
        set workEventTitle to "WORK"
        set replySubject to "自动回复:当前非工作时段"
        set replyContent to "您好,我目前不在工作时间,无法及时响应邮件,会在工作时段第一时间处理您的来信。"
        -- =====================================

        -- 读取目标群组内所有联系人邮箱
        tell application "Contacts"
            set targetGroup to group targetContactGroupName
            set groupEmailList to {}
            repeat with contactPerson in every person of targetGroup
                repeat with emailEntry in every email of contactPerson
                    set end of groupEmailList to (value of emailEntry as lowercase string)
                end repeat
            end repeat
        end tell

        -- 检查当前是否有进行中的WORK事件
        set nowTime to current date
        tell application "Calendar"
            set activeWorkEvents to every event of (every calendar) whose start date ≤ nowTime and end date ≥ nowTime and summary is equal to workEventTitle
            set isWorkInProgress to (count of activeWorkEvents) > 0
        end tell

        -- 非工作时段给目标组发件人发自动回复
        if isWorkInProgress is false then
            repeat with receivedMsg in theMessages
                set rawSender to (sender of receivedMsg as lowercase string)
                -- 提取纯邮箱地址,适配"姓名<邮箱>"格式的发件人字段
                if rawSender contains "<" then
                    set AppleScript's text item delimiters to {"<", ">"}
                    set senderEmail to text item 2 of rawSender
                    set AppleScript's text item delimiters to {""}
                else
                    set senderEmail to rawSender
                end if

                if groupEmailList contains senderEmail then
                    set replyMsg to reply receivedMsg opening window no
                    tell replyMsg
                        set subject to replySubject
                        set content to replyContent
                        send
                    end tell
                end if
            end repeat
        end if
    end perform mail action with messages
end using terms from

脚本编写完成后,按Command+Shift+G在访达中跳转路径~/Library/Application Scripts/,手动新建名为com.apple.mail的文件夹(如果已存在则直接进入),将脚本保存为WorkAutoReply.scpt到该路径下,保存时文件格式选择「脚本」。
首次触发脚本时系统会弹出权限申请,需允许脚本访问邮件、通讯录、日历三个应用,否则逻辑无法正常执行。

2. 配置Mail收信规则

  • 打开Mail应用,进入「设置」-「规则」页,点击「添加规则」
  • 基础筛选条件可按需配置,比如添加「发件人在我的通讯录」减少无效脚本触发,也可留空将所有判断逻辑交由脚本处理
  • 执行动作选择「运行AppleScript」,下拉选中刚才部署的WorkAutoReply.scpt
  • 保存规则,选择不将规则应用到收件箱内已有邮件即可。
可选优化与注意事项
  • 若需要避免短时间内给同一发件人重复发送自动回复,可在脚本开头添加property repliedRecords : "",记录已回复的发件人邮箱与回复时间,设置24小时内同一发件人仅回复一次
  • 该方案不需要Mail保持前台运行,只要Mail在后台常驻(默认开机自启)即可正常触发规则
  • 若WORK事件仅存储在指定日历中,可将脚本内遍历所有日历的逻辑改为遍历指定日历,减少查询开销
  • 不要在脚本中添加耗时过长的逻辑,避免阻塞Mail正常收信流程

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.29 09:39:43