MacOSX:附带附件的新邮件

Alb*_*ert 5 email macos smtp

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

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

open "mailto:dummy@somewhere.com?subject=foo&body=bar"
Run Code Online (Sandbox Code Playgroud)

我现在如何附加文件?

如果这种方式不可能(有open),我的替代方案是什么?

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

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

Pau*_*l R 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
Run Code Online (Sandbox Code Playgroud)

如果您没有任何方法直接运行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
Run Code Online (Sandbox Code Playgroud)

  • 如果用户更喜欢其他邮件客户端,例如 Thunderbird,则 Mail 可能未完全配置,并且启动 Mail 可能会惹恼用户。 (2认同)