GithubHelp home page GithubHelp logo

conmio / react-native-mail Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chirag04/react-native-mail

0.0 5.0 0.0 50 KB

A wrapper on top of MFMailComposeViewController from iOS and Mail Intent on android

License: MIT License

Objective-C 56.16% Java 38.93% Ruby 4.91%

react-native-mail's Introduction

react-native-mail

A React Native wrapper for Apple's MFMailComposeViewController from iOS and Mail Intent on android Supports emails with attachments.

Installation

npm i --save react-native-mail

Add it to your android project

  • In android/setting.gradle
...
include ':RNMail', ':app'
project(':RNMail').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mail/android')
  • In android/app/build.gradle
...
dependencies {
    ...
    compile project(':RNMail')
}
  • register module (in MainActivity.java)
import com.chirag.RNMail.*;  // <--- import

public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
  ......

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mReactRootView = new ReactRootView(this);

    mReactInstanceManager = ReactInstanceManager.builder()
      .setApplication(getApplication())
      .setBundleAssetName("index.android.bundle")
      .setJSMainModuleName("index.android")
      .addPackage(new MainReactPackage())
      .addPackage(new RNMail())              // <------ add here
      .setUseDeveloperSupport(BuildConfig.DEBUG)
      .setInitialLifecycleState(LifecycleState.RESUMED)
      .build();

    mReactRootView.startReactApplication(mReactInstanceManager, "ExampleRN", null);

    setContentView(mReactRootView);
  }

  ......

}

Add it to your iOS project

  1. Run npm install react-native-mail --save
  2. Open your project in XCode, right click on Libraries and click Add Files to "Your Project Name" (Screenshot) then (Screenshot).
  3. Add libRNMail.a to Build Phases -> Link Binary With Libraries (Screenshot).
  4. Whenever you want to use it within React code now you can: var Mailer = require('NativeModules').RNMail;

Example

var Mailer = require('NativeModules').RNMail;

var MailExampleApp = React.createClass({
  handleHelp: function() {
    Mailer.mail({
      subject: 'need help',
      recipients: ['[email protected]'],
      body: '',
      attachment: {
        path: '',  // The absolute path of the file from which to read data.
        type: '',   // Mime Type: jpg, png, doc, ppt, html, pdf
        name: '',   // Optional: Custom filename for attachment
      }
    }, (error, event) => {
        if(error) {
          AlertIOS.alert('Error', 'Could not send mail. Please send a mail to [email protected]');
        }
    });
  },  
  render: function() {
    return (
      <TouchableHighlight
            onPress={row.handleHelp}
            underlayColor="#f7f7f7">
	      <View style={styles.container}>
	        <Image source={require('image!announcement')} style={styles.image} />
	      </View>
	   </TouchableHighlight>
    );
  }
});

Note

On android callback will only have error(if any) as the argument. event is not available on android.

Here is how it looks:

Demo gif

react-native-mail's People

Contributors

chirag04 avatar christopherdro avatar lassebm avatar anttu avatar avishayil avatar ncnlinh avatar richarddewit avatar

Watchers

James Cloos avatar Tommi Liittokivi avatar  avatar  avatar Ville Viskari avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.