问题
I am new to Mac OS X application development, My question is simple, i am able set recipients and body text in default mail application through my application, but i cannot set CC and BCC recipients in the mail application. Is there any way to set CC and BCC through code, i am using Swift. My Code for settings recipients and Body is here
service!.recipients = [self.txtTo.stringValue]
service!.subject = "Subject"
Thanks
回答1:
It's generally much easier to just use a mailto URL for this case - all mail applications support them (and its required as a URL scheme for an app to be registered as an email application).
Here's the schema.
An example would be:
mailto:a@b.com?subject=blah&cc=b@c.com,c@d.com&bcc=d@e.com,e@f.com
You can generate and open this URL using
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"mailto:a@b.com?subject=blah&cc=b@c.com,c@d.com&bcc=d@e.com,e@f.com"]]
回答2:
I had to tinker with it a bit to get it to work in Swift 5. This is what I came up with:
let url = URL.init(string: "mailto:\a@b.com?subject=\(subject)&cc=b@c.com,c@d.com&bcc=d@e.com,e@f.com")
NSWorkspace.shared.open(url!)
来源:https://stackoverflow.com/questions/39660096/nssharingservice-set-cc-and-bcc-recipients-in-default-email-mac-osx-application