react-native-email-link icon indicating copy to clipboard operation
react-native-email-link copied to clipboard

Specifying subject in openComposer throws an error when selecting Default mail reader on iOS

Open karel-suchomel-ed opened this issue 2 years ago • 13 comments

As the title says I'm trying to compose an email using this library with subject and body, but when selecting the Default mail reader it throws an error: [Error: Unable to open URL: file:///private/var/containers/Bundle/Application/23727D6B-B7ED-4C2F-BE2E-85F06F2F9D77/Example.app/mailto:...%3Fsubject=Mobile%20application%20customer%20support. Add file to LSApplicationQueriesSchemes in your Info.plist.]

When I select for example Gmail, it works correctly

If I remove the subject, it works even with the Default mail reader

This is how I'm calling the method

openComposer({
     body,
     subject,
     title: '',
     message: t('modals.email_app.dialog.text'),
     cancelLabel: t('buttons.cancel', {ns: 'general'}),
     to: `mailto:${url}`
   }).catch(() => {
     Alert.alert(t('modals.email_app.title'), t('modals.email_app.text'))
   })

I tried using the default Linking API with mailto:[email protected]?cc=$subject=${subject}&body=${body}and it is resulting in the same error

karel-suchomel-ed avatar Feb 07 '23 10:02 karel-suchomel-ed

the same

react-native version: 0.71.1

odifort avatar Feb 07 '23 15:02 odifort

Anyone find a work around?

martinblampied avatar Mar 01 '23 20:03 martinblampied

Same here! 0.71.3 But it doesn't work even without the subject. On non-default client works fine.

bardaxx avatar Mar 06 '23 08:03 bardaxx

It looks like iOS might now to require adding the mailto scheme to LSApplicationQueriesSchemes. Adding it in your Info.plist should help.

tschoffelen avatar Mar 06 '23 09:03 tschoffelen

It looks like iOS might now to require adding the mailto scheme to LSApplicationQueriesSchemes. Adding it in your Info.plist should help.

Thanks for the reply, in Expo we need to do something in the configuration of the plugin?

Edit:

I've added this via Expo config

{
  "expo": {
    "ios": {
      "infoPlist": {
        "LSApplicationQueriesSchemes": ["mailto"]
      }
    }
  }
}

but still not working

bardaxx avatar Mar 06 '23 09:03 bardaxx

@tschoffelen I had mailto in my plist but still have the same issue. I also added file as per the error message but that didn't fix.

Appears to be something with the subject/body. If I only populate the 'to' it works. If I add a subject or body it fails.

martinblampied avatar Mar 06 '23 09:03 martinblampied

Any update about this? I've installed the latest release of this lib but nothing has changed.

bardaxx avatar Mar 07 '23 12:03 bardaxx

@tschoffelen I had mailto in my plist but still have the same issue. I also added file as per the error message but that didn't fix.

Appears to be something with the subject/body. If I only populate the 'to' it works. If I add a subject or body it fails.

I have the same problem even without the plugin, if I add a subject or body with Linking API the result is the same. 🤔

bardaxx avatar Mar 07 '23 15:03 bardaxx

@karel-suchomel-ed @giacomoalonzi @martinblampied I've made small investigation. Incorrect encoding is the root of this issue. So you can simply encode your subject and body using encodeURIComponent() if your platform is iOS.

openComposer({ to: Emails.SUPPORT_EMAIL, subject: Platform.OS === 'ios' ? encodeURIComponent(yourSubject) : yourSubject, body: Platform.OS === 'ios' ? encodeURIComponent(yourBody) : yourBody, });

Or you can use 'encodeBody: true' if you have problems with body

AndreiBehel avatar Mar 13 '23 08:03 AndreiBehel

@AndreiBehel - sorry for late reply. That worked thanks 👍

martinblampied avatar May 10 '23 10:05 martinblampied

@karel-suchomel-ed @giacomoalonzi @martinblampied I've made small investigation. Incorrect encoding is the root of this issue. So you can simply encode your subject and body using encodeURIComponent() if your platform is iOS.

openComposer({ to: Emails.SUPPORT_EMAIL, subject: Platform.OS === 'ios' ? encodeURIComponent(yourSubject) : yourSubject, body: Platform.OS === 'ios' ? encodeURIComponent(yourBody) : yourBody, });

Or you can use 'encodeBody: true' if you have problems with body

I had the same problem, and this also solved my issue. Thanks @AndreiBehel !

fansilva1991 avatar Jul 11 '23 16:07 fansilva1991

Should we build this into the library? I'm happy to accept a PR for this change

tschoffelen avatar Jul 17 '23 07:07 tschoffelen

Should we build this into the library? I'm happy to accept a PR for this change.

Hi, @tschoffelen I opened a PR ( https://github.com/includable/react-native-email-link/pull/125 ) which adds support to encode the subject.

I hope you guys can review it :)

fansilva1991 avatar Aug 07 '23 00:08 fansilva1991

This issue is stale because it has been open for 60 days with no activity.

github-actions[bot] avatar Mar 30 '24 01:03 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale. Please feel free to re-open if you feel this issue is still relevant.

github-actions[bot] avatar Apr 14 '24 02:04 github-actions[bot]