NSSharingService and default mail client

  • Dear list,

    I'm exploring the use of NSSharingService for emailing (sharing) documents from within my app. It's working fine if the system's default mail client is set to Mail.app. But if it's set to, for example, Thunderbird, nothing happens.

    I also confirmed the same behavior from the Share menu in Pages.app. Works fine for Mail.app, but not for any other mail client I tried. The user is not notified, just nothing happens.

    Is this a bug or a feature?

    I really wish there was a solid way to send a mail from within an app on OS X. With the whole sandbox/applescript debacle, I was hoping that NSSharingService would at least work well on 10.8, but, apart from the 'bug' described above, there seems to be no way to set the recipients or subject of the mail.

    Hoping for enlightenment,

    Martin
  • [I'd accidentally posted my reply off-list. Bringing it back.]

    The times I've autogenerated emails, I did so without thinking of alternate clients. On MacOS, I used -[NSWorkspace openURL:], which can be funky for a long or non-ASCII body, but could be made to work. The system should honor the user's choice for mailto: handlers.

    But that may be hard to integrate with NSSharingService. Perhaps you could fall back on mailto: in the didFail… delegate method.

    — F

    On 21 May 2013, at 12:52 AM, Martin Hewitson <martin.hewitson...> wrote:

    > Hi Fritz,
    >
    > I did take a look at the delegate callbacks, and -sharingService:didFailToShareItems:error: is called when the default client is anything other than Mail.app, but the error is 'empty' so presenting it to the user doesn't reveal what's wrong.
    >
    > More importantly, this sharing by email doesn't seem to work for any other app I tried when the default mail client is not Mail.app. Seems strange to me. Do you have experience of sharing my mail working for, say, Thunderbird? With any app at all?
    >
    > Cheers,
    >
    > Martin
    >
    >
    >
    > On May 20, 2013, at 05:00 PM, Fritz Anderson <fritza...> wrote:
    >
    >> On 19 May 2013, at 8:29 AM, Martin Hewitson <martin.hewitson...> wrote:
    >>
    >>> I'm exploring the use of NSSharingService for emailing (sharing) documents from within my app. It's working fine if the system's default mail client is set to Mail.app. But if it's set to, for example, Thunderbird, nothing happens.
    >>>
    >>> I also confirmed the same behavior from the Share menu in Pages.app. Works fine for Mail.app, but not for any other mail client I tried. The user is not notified, just nothing happens.
    >>>
    >>> Is this a bug or a feature?
    >>>
    >>> I really wish there was a solid way to send a mail from within an app on OS X. With the whole sandbox/applescript debacle, I was hoping that NSSharingService would at least work well on 10.8, but, apart from the 'bug' described above, there seems to be no way to set the recipients or subject of the mail.
    >>
    >> You've described the user-visble behavior, but not the actual behavior of your code.
    >>
    >> Have you registered a delegate and examined the content of -sharingService:willShareItems:, -sharingService:didShareItems:, and -sharingService:didFailToShareItems:error:? Do they get called? With the expected items? If didFail…, what was the error?
    >>
    >> — F
    >>
    >> --
    >> Fritz Anderson
    >> Xcode 4 Unleashed: 4.5 supplement for free!
    >> http://www.informit.com/store/xcode-4-unleashed-9780672333279
    >>
    >
    >
    >
    >
    >

    --
    Fritz Anderson
    Xcode 4 Unleashed: 4.5 supplement for free!
    http://www.informit.com/store/xcode-4-unleashed-9780672333279
  • On May 21, 2013, at 4:30 PM, Fritz Anderson <fritza...> wrote:

    > [I'd accidentally posted my reply off-list. Bringing it back.]
    >
    > The times I've autogenerated emails, I did so without thinking of alternate clients. On MacOS, I used -[NSWorkspace openURL:], which can be funky for a long or non-ASCII body, but could be made to work. The system should honor the user's choice for mailto: handlers.

    OK, I need to read some more about mailto handlers. I dipped my toe in this while trying to figure out how to move away from the my old applescript methods, but I kind of got stuck. I'm assuming one can do attachments in a mailto url?

    >
    > But that may be hard to integrate with NSSharingService. Perhaps you could fall back on mailto: in the didFail… delegate method.

    I've no real desire to use NSSharingService. If I find a way to reliably send a mail (with attachments) then I'll be most delighted.

    Cheers,

    Martin

    >
    > — F
    >
    >
    > On 21 May 2013, at 12:52 AM, Martin Hewitson <martin.hewitson...> wrote:
    >
    >> Hi Fritz,
    >>
    >> I did take a look at the delegate callbacks, and -sharingService:didFailToShareItems:error: is called when the default client is anything other than Mail.app, but the error is 'empty' so presenting it to the user doesn't reveal what's wrong.
    >>
    >> More importantly, this sharing by email doesn't seem to work for any other app I tried when the default mail client is not Mail.app. Seems strange to me. Do you have experience of sharing my mail working for, say, Thunderbird? With any app at all?
    >>
    >> Cheers,
    >>
    >> Martin
    >>
    >>
    >>
    >> On May 20, 2013, at 05:00 PM, Fritz Anderson <fritza...> wrote:
    >>
    >>> On 19 May 2013, at 8:29 AM, Martin Hewitson <martin.hewitson...> wrote:
    >>>
    >>>> I'm exploring the use of NSSharingService for emailing (sharing) documents from within my app. It's working fine if the system's default mail client is set to Mail.app. But if it's set to, for example, Thunderbird, nothing happens.
    >>>>
    >>>> I also confirmed the same behavior from the Share menu in Pages.app. Works fine for Mail.app, but not for any other mail client I tried. The user is not notified, just nothing happens.
    >>>>
    >>>> Is this a bug or a feature?
    >>>>
    >>>> I really wish there was a solid way to send a mail from within an app on OS X. With the whole sandbox/applescript debacle, I was hoping that NSSharingService would at least work well on 10.8, but, apart from the 'bug' described above, there seems to be no way to set the recipients or subject of the mail.
    >>>
    >>> You've described the user-visble behavior, but not the actual behavior of your code.
    >>>
    >>> Have you registered a delegate and examined the content of -sharingService:willShareItems:, -sharingService:didShareItems:, and -sharingService:didFailToShareItems:error:? Do they get called? With the expected items? If didFail…, what was the error?
    >>>
    >>> — F
    >>>
    >>> --
    >>> Fritz Anderson
    >>> Xcode 4 Unleashed: 4.5 supplement for free!
    >>> http://www.informit.com/store/xcode-4-unleashed-9780672333279
    >>>
    >>
    >>
    >>
    >>
    >>
    >
    > --
    > Fritz Anderson
    > Xcode 4 Unleashed: 4.5 supplement for free!
    > http://www.informit.com/store/xcode-4-unleashed-9780672333279
    >
  • On May 21, 2013, at 04:35 PM, Martin Hewitson <martin.hewitson...> wrote:

    >
    > On May 21, 2013, at 4:30 PM, Fritz Anderson <fritza...> wrote:
    >
    >> [I'd accidentally posted my reply off-list. Bringing it back.]
    >>
    >> The times I've autogenerated emails, I did so without thinking of alternate clients. On MacOS, I used -[NSWorkspace openURL:], which can be funky for a long or non-ASCII body, but could be made to work. The system should honor the user's choice for mailto: handlers.
    >
    > OK, I need to read some more about mailto handlers. I dipped my toe in this while trying to figure out how to move away from the my old applescript methods, but I kind of got stuck. I'm assuming one can do attachments in a mailto url?

    OK, after reading some about this, it seems that one can't have attachments with a mailto: handler on OS X. Is that correct? If so, I'm back to my original question: how can I robustly send a mail with the user's default mail client and be able to fill in all the details (recipients, subject, body including attachments). And I need this to work on 10.7 and 10.8. Anyone any good ideas? Seems like this should be a solved problem.

    Many thanks,

    Martin

    >
    >>
    >> But that may be hard to integrate with NSSharingService. Perhaps you could fall back on mailto: in the didFail… delegate method.
    >
    >
    > I've no real desire to use NSSharingService. If I find a way to reliably send a mail (with attachments) then I'll be most delighted.
    >
    > Cheers,
    >
    > Martin
    >
    >>
    >> — F
    >>
    >>
    >> On 21 May 2013, at 12:52 AM, Martin Hewitson <martin.hewitson...> wrote:
    >>
    >>> Hi Fritz,
    >>>
    >>> I did take a look at the delegate callbacks, and -sharingService:didFailToShareItems:error: is called when the default client is anything other than Mail.app, but the error is 'empty' so presenting it to the user doesn't reveal what's wrong.
    >>>
    >>> More importantly, this sharing by email doesn't seem to work for any other app I tried when the default mail client is not Mail.app. Seems strange to me. Do you have experience of sharing my mail working for, say, Thunderbird? With any app at all?
    >>>
    >>> Cheers,
    >>>
    >>> Martin
    >>>
    >>>
    >>>
    >>> On May 20, 2013, at 05:00 PM, Fritz Anderson <fritza...> wrote:
    >>>
    >>>> On 19 May 2013, at 8:29 AM, Martin Hewitson <martin.hewitson...> wrote:
    >>>>
    >>>>> I'm exploring the use of NSSharingService for emailing (sharing) documents from within my app. It's working fine if the system's default mail client is set to Mail.app. But if it's set to, for example, Thunderbird, nothing happens.
    >>>>>
    >>>>> I also confirmed the same behavior from the Share menu in Pages.app. Works fine for Mail.app, but not for any other mail client I tried. The user is not notified, just nothing happens.
    >>>>>
    >>>>> Is this a bug or a feature?
    >>>>>
    >>>>> I really wish there was a solid way to send a mail from within an app on OS X. With the whole sandbox/applescript debacle, I was hoping that NSSharingService would at least work well on 10.8, but, apart from the 'bug' described above, there seems to be no way to set the recipients or subject of the mail.
    >>>>
    >>>> You've described the user-visble behavior, but not the actual behavior of your code.
    >>>>
    >>>> Have you registered a delegate and examined the content of -sharingService:willShareItems:, -sharingService:didShareItems:, and -sharingService:didFailToShareItems:error:? Do they get called? With the expected items? If didFail…, what was the error?
    >>>>
    >>>> — F
    >>>>
    >>>> --
    >>>> Fritz Anderson
    >>>> Xcode 4 Unleashed: 4.5 supplement for free!
    >>>> http://www.informit.com/store/xcode-4-unleashed-9780672333279
    >>>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>
    >> --
    >> Fritz Anderson
    >> Xcode 4 Unleashed: 4.5 supplement for free!
    >> http://www.informit.com/store/xcode-4-unleashed-9780672333279
    >>
    >
    >
    >

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Martin Hewitson
    Albert-Einstein-Institut
    Max-Planck-Institut fuer
        Gravitationsphysik und Universitaet Hannover
    Callinstr. 38, 30167 Hannover, Germany
    Tel: +49-511-762-17121, Fax: +49-511-762-5861
    E-Mail: <martin.hewitson...>
    WWW: http://www.aei.mpg.de/~hewitson
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • On Jun 2, 2013, at 9:37 AM, Martin Hewitson <martin.hewitson...> wrote:

    > OK, after reading some about this, it seems that one can't have attachments with a mailto: handler on OS X. Is that correct?

    Yes, as far as I know.

    > If so, I'm back to my original question: how can I robustly send a mail with the user's default mail client and be able to fill in all the details (recipients, subject, body including attachments). And I need this to work on 10.7 and 10.8. Anyone any good ideas? Seems like this should be a solved problem.

    You can’t do this in a way that supports all mail clients, because there isn’t a common API they all implement for this. You can probably use AppleScript to drive Mail to do this. I don’t know whether any other mail clients support the same suite of AppleEvents.

    (And anyway, in my experience the majority of people who don’t use Apple Mail are using a web-based client like Gmail or Hotmail; in that case there isn’t any local app you could talk to to send a message.)

    —Jens
previous month may 2013 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today