MacOSX: new mail with application

I want to create a new letter with the default email client and automatically attach the file to it.

To create a new email dummy@somewhere.comwith the subject fooand body bar, I can do the following:

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

How can I attach a file now?

If this is not possible in this case (c open), what are my alternatives?

I would prefer a solution that works both in Java and in native languages ​​(C ++, ObjC). Therefore, if there is a way through the shell to do this, it will simplify, because I can just spawn such progress.

Otherwise, I would have to go back to some SMTP engine and just write my own mail sender.

+5
source share
1 answer

You can do it through AppleScript, for example

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

If you cannot run AppleScript directly, you can use it osascriptvia the command line, for example

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
+1
source

All Articles