diff --git a/README.md b/README.md
index 2879936..f0d9597 100644
--- a/README.md
+++ b/README.md
@@ -3,15 +3,23 @@
A React Native wrapper for Apple's ``MFMailComposeViewController`` from iOS and Mail Intent on android
Supports emails with attachments.
-### Installation
+## Installation
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
```bash
-npm i --save react-native-mail
+npm i --save react-native-mail # npm syntax
+yarn add react-native-mail # yarn syntax
```
-### Add it to your android project
+### Automatic Installation
+You can automatically link the native components or follow the manual instructions below if you prefer.
+
+ ```bash
+ react-native link
+ ```
+
+### Manual Installation: Android
* In `android/setting.gradle`
@@ -85,7 +93,7 @@ public class MainApplication extends Application implements ReactApplication {
-### Add it to your iOS project
+### Manual Installation: iOS
1. Run `npm install react-native-mail --save`
2. Open your project in XCode, right click on `Libraries` and click `Add
@@ -97,16 +105,25 @@ public class MainApplication extends Application implements ReactApplication {
## Example
```javascript
-var Mailer = require('react-native-mail');
+/**
+ * Sample React Native App
+ * https://github.com/facebook/react-native
+ * @flow
+ */
+
+import React, { Component } from 'react';
+import { View, Alert, Button } from 'react-native';
+import Mailer from 'react-native-mail';
-var MailExampleApp = React.createClass({
- handleHelp: function() {
+export default class App extends Component {
+
+ handleEmail = () => {
Mailer.mail({
subject: 'need help',
recipients: ['support@example.com'],
ccRecipients: ['supportCC@example.com'],
bccRecipients: ['supportBCC@example.com'],
- body: '',
+ body: 'A Bold Body',
isHTML: true,
attachment: {
path: '', // The absolute path of the file from which to read data.
@@ -114,23 +131,33 @@ var MailExampleApp = React.createClass({
name: '', // Optional: Custom filename for attachment
}
}, (error, event) => {
- if(error) {
- AlertIOS.alert('Error', 'Could not send mail. Please send a mail to support@example.com');
- }
+ Alert.alert(
+ error,
+ event,
+ [
+ {text: 'Ok', onPress: () => console.log('OK: Email Error Response')},
+ {text: 'Cancel', onPress: () => console.log('CANCEL: Email Error Response')}
+ ],
+ { cancelable: true }
+ )
});
- },
- render: function() {
+ }
+
+ render() {
return (
-
-
-
-
-
+
+
+
);
}
-});
+}
+
+
```
### Note
diff --git a/RNMail/RNMail.m b/RNMail/RNMail.m
index c04276f..d7d7dae 100644
--- a/RNMail/RNMail.m
+++ b/RNMail/RNMail.m
@@ -36,9 +36,9 @@ - (dispatch_queue_t)methodQueue
NSString *subject = [RCTConvert NSString:options[@"subject"]];
[mail setSubject:subject];
}
-
+
bool *isHTML = NO;
-
+
if (options[@"isHTML"]){
isHTML = [options[@"isHTML"] boolValue];
}
@@ -57,7 +57,7 @@ - (dispatch_queue_t)methodQueue
NSArray *ccRecipients = [RCTConvert NSArray:options[@"ccRecipients"]];
[mail setCcRecipients:ccRecipients];
}
-
+
if (options[@"bccRecipients"]){
NSArray *bccRecipients = [RCTConvert NSArray:options[@"bccRecipients"]];
[mail setBccRecipients:bccRecipients];
@@ -73,12 +73,23 @@ - (dispatch_queue_t)methodQueue
attachmentName = [[attachmentPath lastPathComponent] stringByDeletingPathExtension];
}
+ // Get the URL string, which is *not* a path (e.g. because it's file:// based)
+ NSString *attachmentURLString = [RCTConvert NSString:options[@"attachment"][@"path"]];
+ // Create a URL from the string
+ NSURL *attachmentURL = [[NSURLComponents componentsWithString:attachmentURLString] URL];
+
// Get the resource path and read the file using NSData
- NSData *fileData = [NSData dataWithContentsOfFile:attachmentPath];
+ NSError *error = nil;
+ NSData *fileData = [NSData dataWithContentsOfURL:attachmentURL options:0 error:&error];
+
+ if(fileData == nil) {
+ // handle error
+ }
+
// Determine the MIME type
NSString *mimeType;
-
+
/*
* Add additional mime types and PR if necessary. Find the list
* of supported formats at http://www.iana.org/assignments/media-types/media-types.xhtml