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?
NSString* subject = @"mail subject";
NSString* body = @"mail body";
NSString* to = @"[email protected]";
NSString *encodedSubject = [NSString stringWithFormat:@"SUBJECT=%@", [subject stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *encodedBody = [NSString stringWithFormat:@"BODY=%@", [body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *encodedTo = [to stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *encodedURLString = [NSString stringWithFormat:@"mailto:%@?%@&%@", encodedTo, encodedSubject, encodedBody];
NSURL *mailtoURL = [NSURL URLWithString:encodedURLString];
[[NSWorkspace sharedWorkspace] openURL:mailtoURL];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With