MacOSX:附带附件的新邮件

时间:2010-10-21 15:19:18

标签: macos email smtp

我想使用默认邮件客户端创建一个新邮件,并自动附加文件。

要创建包含主题dummy@somewhere.com和正文foo的{​​{1}}的新邮件,我可以执行以下操作:

bar

如何立即附加文件?

如果这种方式不可行(使用open "mailto:dummy@somewhere.com?subject=foo&body=bar" ),我的替代方案是什么?

我更喜欢使用Java和本地语言(C ++,ObjC)的解决方案。因此,如果通过shell有一种方法可以做到这一点,这将使我很容易产生这样的进展。

否则我将不得不回到某个SMTP引擎并只写一个自己的小邮件发件人。

1 个答案:

答案 0 :(得分: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