我想从终端开始使用 Mail.app 编写电子邮件,并添加附件。如下所示:
macbook:~ me$ /Applications/Mail.app/Contents/MacOS/Mail -s the_subject -to [email protected] < ~/Downloads/file.zip
答案1
您可以使用 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
用法:compose_email '[email protected]' 'Some Subject' /path/to/attachment.zip
答案2
我知道这是一个老话题,但我发现它非常有用。Josh 编写的代码正是我想要的。唯一的问题是,在我添加延迟之前,它无法在我的 Mac 上运行。如果没有这个,它会发送而不带附件。已更改:
...
delay 1
send MyEmail
end tell
end tell
" | osascript