MacOSX:带附件的新邮件

5

我希望使用默认的邮件客户端创建一封新邮件,并自动将文件附加到邮件中。

要创建一个新邮件,发送给 dummy@somewhere.com ,主题为foo,正文为bar,您可以执行以下操作:

open "mailto:dummy@somewhere.com?subject=foo&body=bar"

如何现在附加文件?

如果这种方式不可行(使用open),我还有哪些选择?

我希望找到一种既能在Java中使用,也能在本地语言(C ++,ObjC)中使用的解决方案。如果可以通过shell执行此操作,那么这将非常容易,因为我只需启动这样的进程即可。

否则,我将不得不退回到某些SMTP引擎,并编写自己的小型邮件发送器。

1个回答

2
您可以通过AppleScript来实现,例如:
tell application "Mail"
    set msg to make new outgoing message with properties {subject:"Test", visible:true}
    tell msg to make new to recipient with properties {address:"someone@somewhere.com"}
    tell msg to make new attachment with properties {file name:"Macintosh HD:Users:me:my_file.txt" as alias}
end tell

如果您没有直接运行AppleScript的方法,那么可以通过命令行使用osascript,例如:
osascript <<EOF
tell application "Mail"
    set msg to make new outgoing message with properties {subject:"Test", visible:true}
    tell msg to make new to recipient with properties {address:"someone@somewhere.com"}
    tell msg to make new attachment with properties {file name:"Macintosh HD:Users:me:my_file.txt" as alias}
end tell
EOF

2
如果用户更喜欢其他的邮件客户端,比如Thunderbird,那么Mail可能没有完全配置好,启动Mail可能会让用户感到烦恼。 - JWWalker

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接