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

如何在MacOS命令行通过Outlook发送带附件的邮件

在macOS命令行通过Outlook自动发送带Excel附件的邮件

mailto协议本身不支持添加附件的参数,所以你之前用open -b com.microsoft.outlook调用mailto的方式没法实现附件需求。要完成这个功能,推荐用AppleScript直接控制Outlook,既能添加附件,也能依托Outlook自身完成身份验证。

方法:使用AppleScript + 命令行执行

  1. 编写AppleScript脚本,实现创建带附件的邮件并发送:
tell application "Microsoft Outlook"
    -- 创建新邮件,设置主题、正文和收件人
    set newMessage to make new outgoing message with properties {¬
        subject:"reports", ¬
        content:"Please find attached reports", ¬
        recipient recipients:{make new recipient with properties {email address:{address:"me@example.com"}}}}
    
    -- 添加Excel附件,替换为你的文件绝对路径
    make new attachment at end of attachments of newMessage with properties {¬
        file name:"/Users/your_username/Documents/your_report.xlsx"}
    
    -- 自动发送邮件;如果想手动确认,替换成`display newMessage`
    send newMessage
end tell
  1. 在命令行直接执行脚本(用osascript命令):
osascript -e 'tell application "Microsoft Outlook" set newMessage to make new outgoing message with properties {subject:"reports", content:"Please find attached reports", recipient recipients:{make new recipient with properties {email address:{address:"me@example.com"}}}} make new attachment at end of attachments of newMessage with properties {file name:"/Users/your_username/Documents/your_report.xlsx"} send newMessage end tell'

注意事项

  • 第一次执行时,Outlook会弹出权限请求,允许脚本控制即可,后续会依托Outlook已登录的账号自动完成身份验证
  • 务必替换脚本中的收件人邮箱、Excel文件绝对路径为实际值
  • 如果不想自动发送,把脚本里的send newMessage替换为display newMessage,会打开Outlook的邮件编辑窗口,你可以检查后手动发送

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 05:58:21