Send Email using React Native iOS

Viewed 5421

I need to be able to send emails using react native.

The user inputs text data into a form and presses the submit button, the text should then be copied into a new email and sent to an address where i can view the data. It will always be sent to the same address.

So basically what i need is sending emails from within the app, while sender and recipient address stay the same for every user. (Not choosable by the user or anything)

I have looked up various modules which seem to be able to do that, but none has worked with react native so far (i.e. https://nodemailer.com)

What i don't need is the standard email prompt of iOS popping up (As in this module https://www.npmjs.com/package/react-native-communications). It should always be done in the background, without the user even knowing an email has been sent, just getting a confirm that the data has been submitted.

2 Answers

I've just created an npm package that allows send user to another email app.

https://github.com/ErickMaeda/react-native-email-action

It's easy to install, and you don't need any native code to link.

Install:

npm install --save react-native-email-action

Usage

import { sendEmail } from 'react-native-email-action';

const options = {
  to: "erick.maeda26@gmail.com", 
  subject: "Very important!", 
  body: "Verify your email fast!"
};
sendMail(options);

Important

After iOS 9+, you need to add this information keys on Info.plist

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>message</string>
  <string>ms-outlook</string>
  <string>googlegmail</string>
</array>    
Related