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

别说谁变了你拦得住时间么 提交于 2019-12-23 15:22:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!