4

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.

bbasti
  • 43
  • 1
  • 4
  • This seems more like a Swift or Objective-C issue. http://stackoverflow.com/questions/29034099/sending-an-automatic-email-with-swift-and-xcode-6, and if it is even possible to do it the way you want, you'd have to write a module and expose it to React Native http://moduscreate.com/swift-modules-for-react-native/. – dannyjolie Mar 26 '16 at 11:58
  • Alright thank you, it would be really convenient if this would work in react alone, but if it's impossible i'll have to go find another way to do it (probably by implementing a custom Swift module) – bbasti Mar 26 '16 at 12:06

2 Answers2

2

Unfortunately, iOS doesn't support to mail in background by default.

What you can do - is to make an XHR request to your backend with a data you need and process a mailing procedure on the server.

Probably you'll find more handy information here:

UPD: You can also try to use iphone smtp client library directly. It means that you need to create a react-native module that will bridge SMTP functionality to the JS part. But here you'll need to store some private credentials in the code which makes them vulnerable to reverse-engineering.

Community
  • 1
  • 1
Alexey Kureev
  • 1,978
  • 15
  • 25
1

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>    
Erick Maeda
  • 329
  • 1
  • 10