I’m trying to use this example provided by @Jürg_Otter to create an email with an attachment. The email creation works, but the attachment doesn’t appear. I’ve tried it against Mail, Outlook and Gmail with the same results on each.
Jürg, or anyone else, can you help me figure out what’s wrong?
Mail.app (which is the default mail application on this machine) is being launched, a new message with all recipients, subject, content and the selected png appears (which is what is expected)
You could try that. And it that works for you, too - then explain in more detail (or code) what you are doing differently when “it doesn’t work”. That would be a start to help figuring out why “it doesn’t work”, and what might be done so that “it works”. Until a new (customer/machine) situation arises - and the what-how-exactly-ah-that’s-why process starts again.
Tried it and it does work with Apple Mail. But for anything else I tried (Outlook, Canary, Made for Gmail) it fails the canPerformWithItems test. If I remove that test, then the result is the same as my earlier attempts - an email is created but the attachment is not there.
I think I read somewhere that NSSharingService only works (correctly?) with Apple’s own services. Is this true? If so, then it is a dead end for my purposes.
Interesting note and possible clue: The Mac versions of Word and Excel can successfully compose an email with the current document attached (even an unsaved document) to Outlook and Canary. But not for Gmail (or a Chrome Gmail wrapper like Made for Gmail) - for which it produces the message “Your default mail client Made for Gmail doesn’t support attachments”.
As far as I remember, NSSharingService works nicely in Apple’s Universe.
When it comes to 3rd party applications, it has it’s limitation - such as you’ve notice.
And it’s entirely up to Apple what that Framework can and can’t do.
At least the example I’ve provided works as expected for it’s intended purpose (how to use NSSharingService with Xojo).
If you care to explain your purposes, you might get some answers by others. Christian has already mentioned one different approach.
It’s certainly more tricky trying to “control” a 3rd party application - to set up a pre-composed Message, which the user can edit before sending in another application.
It might turn out that your best chance is to send the Email yourself from right within your app… and in that case Curl (from MBS) is what we are using.
For the immediate case, I need to compose a message with attachment in the user’s default email client that they can modify before sending, which may include adding recipients not available in my app (and no desire to add by the client) and adding additional attachments. Plus, they want the message to be in the sent folder of their default email client. So, these requirements exclude direct emailing from my app.
Then I wonder what Microsoft is using? It seems to be some type of API since it can report when a given app can’t accept attachments (at least from said API).
This is expected behavior with recent versions of the macOS. Apple no longer supports 3rd Party Mail Clients for NSSharingServices. Just like it no longer supports Social Media with NSSharingServices.
It’s something that I’ve been very vocal about, but probably won’t change until Apple upgrade their CEO to someone who gives a #### about Apple’s products.
If you want to provide a universal solution, you need to go back to early 2000s and via Apple Script and create scripts per e-mail client. With some additional declares you can figure out which e-mail client the customer prefer, but the rest you have to do yourself.