3.0.6 • Published 6 years ago
rn-better-mail v3.0.6
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
- Run
npm install react-native-mail --save
- Open your project in XCode, right click on
Libraries
and clickAdd Files to "Your Project Name"
(Screenshot) then navigate to node_modules/react-native-mail and select RNMail.xcodeproj (Screenshot). - Add
libRNMail.a
toBuild Phases -> Link Binary With Libraries
(Screenshot). - 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!