NSSharingService with email for 3rd-party apps

I have a couple of questions about NSSharingService, specifically with NSSharingServiceNameComposeEmail:


1) I use [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeMessage], then set the correct parameters and call `performWithItems` on it. This works fine if the Mail app is configured to be the "Default email reader" in Mail.app's Preferences. If I change this to some of the other email clients I have, this doesn't work anymore. I have tried MS Outlook, Airmail and Unibox apps, and this doesn't work in any of them. Is this intentional? Does the sharing service with NSSharingServiceNameComposeMessage only work for Mail.app?


2) If that isn't the case, and other apps can be responsible for composing emails as well, what does an app have to do to handle this? If I want to set myself as an email client app, and let others call ComposeMessage, what API should I implement?


If anyone has an idea on how to do this, would really appreciate the help.


Thanks.

Post not yet marked as solved Up vote post of zulfishah Down vote post of zulfishah
1.9k views

Replies

Hi ZulfiShah,


I am facing the same issue.


1.

My investigation tells me that, this is the expected behaviour.

Additionally, if you add an if clause like:

if ([ sharingServiceObject canPerformWithItems:shareItems])

it will not enter the if condition unless the default client selected is the Mail app


2.

A workaround for the same could be detecting the default mail app through apple script and running a suitable script for that app. And use MailTo in cases where you can't detect the default mail client.


This isn't a robust solution as you never know what client could the user use and the script for each client would be different.


For further reading:

http://lists.apple.com/archives/cocoa-dev/2011/Feb/msg00020.html

As of February 2023, this code DOES launch Outlook, but will NOT attach a document to the Outlook-created email:

` NSString* msgText = @"This is text for the body of the email"; NSMutableAttributedString *maStr = [[NSMutableAttributedString alloc] initWithString:msgText attributes:@{ } ];

NSSharingService* mailShare = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeEmail];
NSArray* shareItems = @[maStr, fileToSendURL];

[mailShare performWithItems:shareItems];`

Anyone?

I have this problem too. Thunderbird is another email client that does not receive attachments, even though canPerformWithItems: returns YES and the delegate's error callback is not called. I've filed FB13507726 about it.