├── .flowconfig ├── .gitignore ├── LICENSE ├── README.md ├── RNMail.xcodeproj └── project.pbxproj ├── RNMail ├── RNMail.h └── RNMail.m ├── add-xcodeproj.png ├── android ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── chirag │ │ └── RNMail │ │ ├── RNMail.java │ │ ├── RNMailFileProvider.java │ │ └── RNMailModule.java │ └── res │ └── xml │ └── provider_paths.xml ├── index.d.ts ├── index.js ├── package-lock.json ├── package.json ├── react-native-mail.podspec └── screenshot.png /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | 3 | # We fork some components by platform. 4 | .*/*.web.js 5 | .*/*.android.js 6 | 7 | # Some modules have their own node_modules with overlap 8 | .*/node_modules/node-haste/.* 9 | 10 | # Ignore react-tools where there are overlaps, but don't ignore anything that 11 | # react-native relies on 12 | .*/node_modules/react-tools/src/vendor/core/ExecutionEnvironment.js 13 | .*/node_modules/react-tools/src/browser/eventPlugins/ResponderEventPlugin.js 14 | .*/node_modules/react-tools/src/browser/ui/React.js 15 | .*/node_modules/react-tools/src/core/ReactInstanceHandles.js 16 | .*/node_modules/react-tools/src/event/EventPropagators.js 17 | .*/node_modules/flux/lib/invariant.js 18 | 19 | # Ignore jest 20 | .*/node_modules/jest-cli/.* 21 | 22 | # Ignore examples 23 | .*/Examples/.* 24 | 25 | [include] 26 | 27 | [libs] 28 | node_modules/react-native/Libraries/react-native/react-native-interface.js 29 | interfaces.js 30 | 31 | [options] 32 | module.system=haste 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | project.xcworkspace 24 | 25 | # node.js 26 | # 27 | node_modules/ 28 | npm-debug.log 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Chirag Jain 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-mail 2 | 3 | A React Native wrapper for Apple's ``MFMailComposeViewController`` from iOS and Mail Intent on android 4 | Supports emails with attachments. 5 | 6 | ## Installation 7 | 8 | There was a breaking change in RN >=40. So for React Native >= 0.40: use v3.x and higher of this lib. otherwise use v2.x 9 | 10 | ```bash 11 | npm i --save react-native-mail # npm syntax 12 | yarn add react-native-mail # yarn syntax 13 | ``` 14 | 15 | ### Automatic Installation 16 | You can automatically link the native components or follow the manual instructions below if you prefer. 17 | 18 | ```bash 19 | react-native link 20 | ``` 21 | 22 | ### Manual Installation: Android 23 | 24 | * In `android/setting.gradle` 25 | 26 | ```gradle 27 | ... 28 | include ':RNMail', ':app' 29 | project(':RNMail').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mail/android') 30 | ``` 31 | 32 | * In `android/app/build.gradle` 33 | 34 | ```gradle 35 | ... 36 | dependencies { 37 | ... 38 | compile project(':RNMail') 39 | } 40 | ``` 41 | 42 | * if MainActivity extends Activity: register module in MainActivity.java 43 | 44 | 45 | ```java 46 | import com.chirag.RNMail.*; // <--- import 47 | 48 | public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler { 49 | ...... 50 | 51 | @Override 52 | protected void onCreate(Bundle savedInstanceState) { 53 | super.onCreate(savedInstanceState); 54 | mReactRootView = new ReactRootView(this); 55 | 56 | mReactInstanceManager = ReactInstanceManager.builder() 57 | .setApplication(getApplication()) 58 | .setBundleAssetName("index.android.bundle") 59 | .setJSMainModuleName("index.android") 60 | .addPackage(new MainReactPackage()) 61 | .addPackage(new RNMail()) // <------ add here 62 | .setUseDeveloperSupport(BuildConfig.DEBUG) 63 | .setInitialLifecycleState(LifecycleState.RESUMED) 64 | .build(); 65 | 66 | mReactRootView.startReactApplication(mReactInstanceManager, "ExampleRN", null); 67 | 68 | setContentView(mReactRootView); 69 | } 70 | 71 | ...... 72 | 73 | } 74 | ``` 75 | * else if MainActivity extends ReactActivity: register module in `MainApplication.java` 76 | 77 | ```java 78 | import com.chirag.RNMail.*; // <--- import 79 | 80 | public class MainApplication extends Application implements ReactApplication { 81 | .... 82 | 83 | @Override 84 | protected List getPackages() { 85 | return Arrays.asList( 86 | new MainReactPackage(), 87 | new RNMail() // <------ add here 88 | ); 89 | } 90 | }; 91 | 92 | ``` 93 | 94 | 95 | 96 | ### Manual Installation: iOS 97 | 98 | 1. Run `npm install react-native-mail --save` 99 | 2. Open your project in XCode, right click on `Libraries` and click `Add 100 | Files to "Your Project Name"` [(Screenshot)](http://url.brentvatne.ca/jQp8) then navigate to node_modules/react-native-mail and select RNMail.xcodeproj [(Screenshot)](https://github.com/pedramsaleh/react-native-mail/blob/master/add-xcodeproj.png?raw=true). 101 | 3. Add `libRNMail.a` to `Build Phases -> Link Binary With Libraries` 102 | [(Screenshot)](http://url.brentvatne.ca/17Xfe). 103 | 4. Whenever you want to use it within React code now you can: `var Mailer = require('NativeModules').RNMail;` 104 | 105 | 106 | ## Example 107 | ```javascript 108 | /** 109 | * Sample React Native App 110 | * https://github.com/facebook/react-native 111 | * @flow 112 | */ 113 | 114 | import React, { Component } from 'react'; 115 | import { View, Alert, Button } from 'react-native'; 116 | import Mailer from 'react-native-mail'; 117 | 118 | export default class App extends Component { 119 | 120 | handleEmail = () => { 121 | Mailer.mail({ 122 | subject: 'need help', 123 | recipients: ['support@example.com'], 124 | ccRecipients: ['supportCC@example.com'], 125 | bccRecipients: ['supportBCC@example.com'], 126 | body: 'A Bold Body', 127 | customChooserTitle: 'This is my new title', // Android only (defaults to "Send Mail") 128 | isHTML: true, 129 | attachments: [{ 130 | // Specify either `path` or `uri` to indicate where to find the file data. 131 | // The API used to create or locate the file will usually indicate which it returns. 132 | // An absolute path will look like: /cacheDir/photos/some image.jpg 133 | // A URI starts with a protocol and looks like: content://appname/cacheDir/photos/some%20image.jpg 134 | path: '', // The absolute path of the file from which to read data. 135 | uri: '', // The uri of the file from which to read the data. 136 | // Specify either `type` or `mimeType` to indicate the type of data. 137 | type: '', // Mime Type: jpg, png, doc, ppt, html, pdf, csv 138 | mimeType: '', // - use only if you want to use custom type 139 | name: '', // Optional: Custom filename for attachment 140 | }] 141 | }, (error, event) => { 142 | Alert.alert( 143 | error, 144 | event, 145 | [ 146 | {text: 'Ok', onPress: () => console.log('OK: Email Error Response')}, 147 | {text: 'Cancel', onPress: () => console.log('CANCEL: Email Error Response')} 148 | ], 149 | { cancelable: true } 150 | ) 151 | }); 152 | } 153 | 154 | render() { 155 | return ( 156 | 157 |