从终端用 Mail.app 写一封带有附件的电子邮件

Der*_*ops 2 mac terminal.app apple-mail

我想从终端开始用 Mail.app 写一封电子邮件,并添加一个附件。像这样的东西:

macbook:~ me$ /Applications/Mail.app/Contents/MacOS/Mail -s the_subject -to email@domain.com < ~/Downloads/file.zip
Run Code Online (Sandbox Code Playgroud)

Jos*_*osh 5

您可以使用 AppleScript 执行此操作。这是一个快速(经过快速测试)的 bash 脚本,它与您想要的很接近。

#!/bin/bash
echo "tell application \"Mail\"
    activate

    set MyEmail to make new outgoing message with properties {visible:true, subject:\"$2\", content:\"Some Message Here\"}
    tell MyEmail
        make new to recipient at end of to recipients with properties {address:\"$1\"}
        make new attachment with properties {file name:((\"$3\" as POSIX file) as alias)}
    end tell
end tell
" | osascript
Run Code Online (Sandbox Code Playgroud)

用法: compose_email 'email@domain.com' 'Some Subject' /path/to/attachment.zip