3.0.6 • Published 6 years ago

rn-better-mail v3.0.6

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

rn-better-mail

Fork of react-native-mail

Installation

npm i --save rn-better-mail # npm syntax

Automatic Installation

You can automatically link the native components or follow the manual instructions below if you prefer.

react-native link

Manual Installation: Android

  • 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')
}
  • if MainActivity extends Activity: 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);
  }

  ......

}
  • else if MainActivity extends ReactActivity: register module in MainApplication.java
import com.chirag.RNMail.*; // <--- import

public class MainApplication extends Application implements ReactApplication {
    ....

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new RNMail()      // <------ add here
      );
    }
  };

Manual Installation: iOS

  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 navigate to node_modules/react-native-mail and select RNMail.xcodeproj (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;

API

  import Mailer from 'rn-better-mail';
  Mailer.mail(mailPreferences, callback);

  interface mailPreferences {
    subject: string,
    recipients: string,
    ccRecipients: string,
    bccRecipients: string,
    body: string | HTML,
    isHtml: boolean // Be sure to set this flag to true, if the body is HTML
    attachments: Array<{
      path: string, // The absolute path of the file from which to read data
      type: string, // Mime Type: jpg, png, doc, ppt, html, pdf
      name: string
    }>
  }

Note

On Android, the callback will only be called if an error occurs. The event argument is unused!

Here is how it looks:

Demo gif