I’d like to open Mail.app and specify a Subject and a File to attach. I can do either independently but not both.
To set the subject I can just form a mailto: string and NSWorkspace openURL that.
To set an attachment I can use
[[NSWorkspace sharedWorkspace] openFile:resolvedPath withApplication:@"Mail"];
I’m not aware of a equivalent to iOS’s MFMailComposeViewController for the Mac. What are my options?
Edit: The original code this linked to has been removed, so I’ve copied some of it to this answer instead.
You can use AppleScript (or Apple Events) to drive Mail.app. This has the advantage that there is no limit to the size of attachments you can pass around, and avoids constructing huge URLs.
In our software, we use the following to compile a suitable AppleScript:
then you can trigger the functions in the script using code like this
The
-constructMessage:headers:method, above, will cause Mail to open a new e-mail with everything already filled in, while the-deliverMessage:headers:method will create and send the e-mail in one hit.