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
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:[email protected]?subject=blah&[email protected],[email protected]&[email protected],[email protected]
You can generate and open this URL using
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"mailto:[email protected]?subject=blah&[email protected],[email protected]&[email protected],[email protected]"]]
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:\[email protected]?subject=\(subject)&[email protected],[email protected]&[email protected],[email protected]")
NSWorkspace.shared.open(url!)
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