Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSSharingService set CC and BCC recipients in Default Email MAC OSX Application

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

like image 205
Shuja Avatar asked Sep 23 '16 11:09

Shuja


2 Answers

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]"]]
like image 91
Dev Sanghani Avatar answered Sep 23 '22 19:09

Dev Sanghani


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!)
like image 30
KPDover Avatar answered Sep 26 '22 19:09

KPDover