Comments (14)
For anyone else stuck on this, you'll have to write a native module as such:
public class NativeModuleSendEmail extends ReactContextBaseJavaModule {
public NativeModuleSendEmail(ReactApplicationContext reactContext) {
super(reactContext);
}
@Override
public String getName() {
return "SendEmail";
}
@ReactMethod
public void sendEmail(final String emailAddress, final String subject) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL , new String[] { emailAddress });
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
getCurrentActivity().startActivity(Intent.createChooser(intent, ""));
}
public static class ReactPackage implements com.facebook.react.ReactPackage {
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new NativeModuleSendEmail(reactContext));
return modules;
}
}
}
Then register it:
return Arrays.<ReactPackage>asList(
new NativeModuleSendEmail.ReactPackage()
);
Create the JS file
/**
* @providesModule send-email
*/
// @flow
import { NativeModules } from 'react-native';
module.exports = NativeModules.SendEmail;
Use it:
import SendMail from 'send-email';
SendMail.sendEmail('some@email', subject);
from react-native-mail.
I also posted a stackoverflow question:
from react-native-mail.
use Linking
module from react native for that.
from react-native-mail.
@chirag04 I can't find an example of this anywhere using Linking
. Do you have one?
from react-native-mail.
http://facebook.github.io/react-native/releases/0.42/docs/linking.html#openurl
from react-native-mail.
Right, but do you know the value that should be passed in to openURL
to open the Mail app?
from react-native-mail.
I'm looking into this more and seeing the idea here. For iOS, we're supposed to pass the URL scheme for iOS. This works well to detect if the user has different mail clients installed as iOS doesn't allow you to change the default Mail app. So, if the user had Inbox for iOS installed, we can detect if that's there first, and then open that:
var Mailer = require('NativeModules').RNMail;
if (Platform.OS === `ios`) {
const inbox = await Linking.canOpenURL(`inbox-gmail:`);
// if inbox is installed, open that
if (inbox) {
Linking.openURL(`inbox-gmail:`);
} else {
// else default to iOS Mail app
Linking.openURL(`message:`);
}
} else if (Platform.OS === `android`) {
// open default mail app via exposed method for Android via logic like: http://stackoverflow.com/a/31594815/1681896
// Mailer.openDefaultClient();
}
For Android, we could use the intent url, but defaulting to the default mail app would be pretty easy via this made-up openDefaultClient
method that would use a solution similar to http://stackoverflow.com/a/31594815/1681896
from react-native-mail.
For the record, as I mentioned above, the iOS conditional I have works perfect. However, besides mailto:
(which opens a new message and that's the opposite of this feature request), I can't figure out a value to pass into openURL
that will launch any kind of mail application on my Android device. I've tried com.google.android.gm
per http://stackoverflow.com/a/3592060/1681896 to try and get it to launch Gmail but with no success
from react-native-mail.
@dwilt did you find a solution to opening the mail app for both ios and android? I want to launch mail app to guide user to verify email upon account creation. Linking.openURL(message:
); or Linking.openURL(inbox-gmail:
); both lead to unhandled exception errors.
from react-native-mail.
@jasan-s no, I wasn't able to find one. We ended up abandoning the idea of opening the mail client automatically since the email notification coming in from the top added to the user experience of them seeing the email come in just as we showed the success message of saying we sent one.
from react-native-mail.
from react-native-mail.
Would like to say that Linking.openURL('mailto:[email protected]?subject=abcdefg&body=body') worked for me, but only on iOS, when I was on simulator it didn't.. threw error
from react-native-mail.
@OllyDixon How to handle this for iOS?
from react-native-mail.
@roots-ai I no longer do React Native. We have migrated onto Flutter.
from react-native-mail.
Related Issues (20)
- TypeScript typings not quite right HOT 2
- In ios not opening mail HOT 3
- Android 11 Mail Attachment Is Not Working HOT 1
- accept file:// uri as path for attachment HOT 1
- New release with URI support HOT 1
- Support promises
- callback not called when activity starts
- pdf not getting attached to mail in higher version androids HOT 3
- Version in npm is not updated HOT 1
- Attachment Images is not working give uri permission error
- How to exclude Paypal from email chooser list? (Android)
- `name` does not work with Android attachments (but works on iOS)
- Does not work on IOS 14.8.1 HOT 2
- MFMailComposeViewController is not dismissing after tap cancel or send button
- not_available error in Android 11 (SDK 30) ? HOT 1
- Android 13 : Unable to launch email window and App "refreshes" HOT 6
- sending an email with attachments using 'react-native-mail' library works but didn't receive email
- Error : not_available in Android 13 with only GMail App HOT 9
- Error : not_available in Android 13 with several emailing app HOT 2
- The library sending email only if logged with gmail account (IOS) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-mail.