簡體   English   中英

MacOSX:附帶附件的新郵件

[英]MacOSX: new mail with attachment

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

要創建一個帶有主題foo和body bar dummy@somewhere.com的新郵件,我可以執行以下操作:

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

我現在如何附加文件?

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

我更喜歡使用Java和本地語言(C ++,ObjC)的解決方案。 因此,如果有一種方法通過shell來做到這一點,這將使我很容易,因為我可以產生這樣的進展。

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

您可以通過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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM