0

I am trying to send email from my application, This is the code:

 sharePhraseToGmail = async () => {


    let url = `mailto:xxx@gmail.com`

    const query = qs.stringify({
      subject:'xxx',
      body:'xxxx',     
    })

    if (query.length) {
      url += `?${query}`;
  }

    try {
       Linking.openURL(url)
    } catch (e) {
      console.log('--------e',e)
    }


  }

No matter what I pass, wrong or real email it gives me this error

     Possible Unhandled Promise Rejection (id: 1):
Error: Unable to open URL: mailto:xxx@gmail.com?subject=xxx&body=xxxx

Or : Add mailto in info.plist

I followed the second error and updated my info.plist like this:

<key>LSApplicationQueriesSchemes</key>
        <array>
            <string>mailto</string>
        </array>

I also tried to use libraries such as react-native-mail and react-native-email but I got the same error on both of them.

Any suggestions on why is this happening?

React native version:0.63.4 Emulator : Iphone 11

user14587589
  • 449
  • 3
  • 19
  • 2
    Refer here https://stackoverflow.com/a/49009072/11560232 react native Linking doesn't work in iOS simulator. You need a real device for testing. – Padmini S Feb 17 '21 at 09:10

0 Answers0