[英]OS X: open e-mail client, create new mail and add file as attachment
[英]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.