├── screenshot.png ├── add-xcodeproj.png ├── index.js ├── RNMail ├── RNMail.h └── RNMail.m ├── android ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── chirag │ │ │ └── RNMail │ │ │ ├── RNMailFileProvider.java │ │ │ ├── RNMail.java │ │ │ └── RNMailModule.java │ │ ├── res │ │ └── xml │ │ │ └── provider_paths.xml │ │ └── AndroidManifest.xml └── build.gradle ├── .gitignore ├── index.d.ts ├── package.json ├── react-native-mail.podspec ├── .flowconfig ├── LICENSE ├── README.md └── RNMail.xcodeproj └── project.pbxproj /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chirag04/react-native-mail/HEAD/screenshot.png -------------------------------------------------------------------------------- /add-xcodeproj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chirag04/react-native-mail/HEAD/add-xcodeproj.png -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import { NativeModules } from 'react-native'; 2 | 3 | export default NativeModules.RNMail; 4 | -------------------------------------------------------------------------------- /RNMail/RNMail.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface RNMail : NSObject 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /android/src/main/java/com/chirag/RNMail/RNMailFileProvider.java: -------------------------------------------------------------------------------- 1 | package com.chirag.RNMail; 2 | 3 | import androidx.core.content.FileProvider; 4 | 5 | public class RNMailFileProvider extends FileProvider { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /android/src/main/res/xml/provider_paths.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | export namespace Mailer { 2 | function mail(options: { 3 | subject?: string; 4 | recipients?: string[]; 5 | ccRecipients?: string[]; 6 | bccRecipients?: string[]; 7 | body?: string; 8 | customChooserTitle?: string; 9 | isHTML?: boolean; 10 | attachments?: { 11 | path?: string; // Specify either 'path' or 'uri' 12 | uri?: string; 13 | type?: string; // Specify either 'type' or 'mimeType' 14 | mimeType?: string; 15 | name?: string; 16 | }[] 17 | }, callback: ( 18 | error: string, 19 | event?: string 20 | ) => void): void; 21 | } 22 | 23 | export default Mailer; 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-mail", 3 | "version": "6.1.1", 4 | "description": "A wrapper on top of MFMailComposeViewController from iOS and Mail Intent on android", 5 | "author": { 6 | "name": "Chirag Jain", 7 | "email": "jain_chirag04@yahoo.com", 8 | "url": "http://chiragjain.tumblr.com" 9 | }, 10 | "license": "MIT", 11 | "repository": { 12 | "type": "git", 13 | "url": "git@github.com:chirag04/react-native-mail.git" 14 | }, 15 | "keywords": [ 16 | "react", 17 | "react-native", 18 | "react-component", 19 | "ios", 20 | "android", 21 | "email", 22 | "MFMailComposeViewController" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion project.hasProperty('compileSdkVersion') ? project.compileSdkVersion : 23 5 | buildToolsVersion project.hasProperty('buildToolsVersion') ? project.buildToolsVersion : "23.0.1" 6 | 7 | defaultConfig { 8 | minSdkVersion 21 9 | targetSdkVersion project.hasProperty('targetSdkVersion') ? project.targetSdkVersion : 22 10 | versionCode 1 11 | versionName "1.0" 12 | ndk { 13 | abiFilters "armeabi-v7a", "x86" 14 | } 15 | } 16 | } 17 | 18 | dependencies { 19 | implementation 'com.facebook.react:react-native:+' 20 | } 21 | -------------------------------------------------------------------------------- /react-native-mail.podspec: -------------------------------------------------------------------------------- 1 | require 'json' 2 | pjson = JSON.parse(File.read('package.json')) 3 | 4 | Pod::Spec.new do |s| 5 | 6 | s.name = pjson["name"] 7 | s.version = pjson["version"] 8 | s.homepage = "https://github.com/chirag04/react-native-mail" 9 | s.summary = pjson["description"] 10 | s.license = pjson["license"] 11 | s.author = { "Chirag Jain" => "jain_chirag04@yahoo.com" } 12 | s.platform = :ios, "7.0" 13 | s.source = { :git => "https://github.com/chirag04/react-native-mail", :tag => "v#{s.version}" } 14 | s.source_files = 'RNMail/*.{h,m}' 15 | 16 | s.dependency 'React-Core' 17 | 18 | end 19 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 15 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /android/src/main/java/com/chirag/RNMail/RNMail.java: -------------------------------------------------------------------------------- 1 | package com.chirag.RNMail; 2 | 3 | import java.util.Arrays; 4 | import java.util.ArrayList; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | import com.facebook.react.ReactPackage; 9 | import com.facebook.react.bridge.NativeModule; 10 | import com.facebook.react.bridge.ReactApplicationContext; 11 | import com.facebook.react.uimanager.ViewManager; 12 | import com.facebook.react.bridge.JavaScriptModule; 13 | 14 | public class RNMail implements ReactPackage { 15 | 16 | @Override 17 | public List createNativeModules( 18 | ReactApplicationContext reactContext) { 19 | List modules = new ArrayList(); 20 | 21 | modules.add(new RNMailModule(reactContext)); 22 | 23 | return modules; 24 | } 25 | 26 | // Deprecated RN 0.47 27 | public List> createJSModules() { 28 | return Collections.emptyList(); 29 | } 30 | 31 | @Override 32 | public List createViewManagers( 33 | ReactApplicationContext reactContext) { 34 | return Collections.emptyList(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /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 |