简体   繁体   中英

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

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!.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM