2010-10-21 34 views
5

我想用默認郵件客戶端創建一封新郵件並自動附加一個文件。MacOSX:帶附件的新郵件

要創建新的郵件[email protected]主題爲foo和身體bar,我可以做到以下幾點:

open "mailto:[email protected]?subject=foo&body=bar" 

如何我現在可以附加文件?

如果這種方式不可行(與open),我的替代方案是什麼?

我寧願使用Java和本地語言(C++,ObjC)工作的解決方案。所以如果有一種方法可以通過shell來做到這一點,那麼這會讓我變得容易,因爲我可以產生這樣的進展。

否則,我將不得不退回到一些SMTP引擎,只寫一個自己的小郵件發件人。

回答

1

你可以通過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:"[email protected]"} 
    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:"[email protected]"} 
    tell msg to make new attachment with properties {file name:"Macintosh HD:Users:me:my_file.txt" as alias} 
end tell 
EOF 
+2

如果用戶喜歡其他郵件客戶端,如Thunderbird,那麼郵件可能沒有完全配置,啓動郵件可能會惹惱用戶。 – JWWalker 2010-10-21 16:26:34