How can we add attachment to default mail Application Using NSWorkSpace in cocoa Mac OSX application

不打扰是莪最后的温柔 提交于 2019-12-10 19:06:25

问题


I am using NSWorkspace to set TO, CC, BCC , SUBJECT and body text in default mail application through my application. How can i add attachments using NSWrokSpace? Is there any way to attach files in the default mail app using NSWorkSpace? I have tried using NSSharingService but problem with NSSharingService is that you cannot set CC and BCC email addresses in the default application Email Compose. Is there any way to add CC, and BCC recipients using NSSharingSerivce ?? or is there any way to add attachments in mail using NSWorkSpace?? My code to open and set TO, CC and BCC is here

 NSWorkspace.sharedWorkspace().openURL(NSURL.init(string:"mai‌​lto:(self.txtTo.‌​stringValue)"+"?subj‌​ect=YourSubject"+"&c‌​c="+self.txtCC.strin‌​gValue+"&bcc="+self.‌​txtBcc.stringValue)!‌​)

And Using NSSharingService i can set only recipients as TO

 service!.recipients = [self.txtTo.stringValue]
 service!.subject = "Subject"

thanks!.


回答1:


It looks like NSSharingService has the method performWithItems, which takes an array of the things you want to share.

It appears you can create a sharing service of type NSSharingServiceNameComposeEmail and then attach a message body and a file to attach.

I've never used NSSharingService before, so the above is based on some Googling and reading the docs. (And I mostly work in iOS these days so my Mac OS is getting a little stale.)

Check out this link:

http://cutecoder.org/featured/programmatically-sending-rich-text-mail-attachment-mac/



来源:https://stackoverflow.com/questions/39778223/how-can-we-add-attachment-to-default-mail-application-using-nsworkspace-in-cocoa

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