tschoffelen / react-native-email-link

📭 Open an email client from React Native (for 'magic link' type functionality).
MIT License
412 stars 74 forks source link

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

Closed karel-suchomel-ed closed 7 months ago

karel-suchomel-ed commented 1 year ago

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@email.com?cc=$subject=${subject}&body=${body}and it is resulting in the same error

animmore commented 1 year ago

the same

react-native version: 0.71.1

martinblampied commented 1 year ago

Anyone find a work around?

giacomoalonzi commented 1 year ago

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

tschoffelen commented 1 year ago

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

giacomoalonzi commented 1 year ago

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

martinblampied commented 1 year ago

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

giacomoalonzi commented 1 year ago

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

giacomoalonzi commented 1 year ago

@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. 🤔

AndreiBehel commented 1 year ago

@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

martinblampied commented 1 year ago

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

fansilva1991 commented 1 year ago

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

tschoffelen commented 1 year ago

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

fansilva1991 commented 1 year ago

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 :)

github-actions[bot] commented 7 months ago

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

github-actions[bot] commented 7 months ago

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.