react-native-mail
react-native-mail copied to clipboard
Added URI support
Currently, emails cannot be attached on android unless the attachment is on an external storage. This can be resolved by:
-
Using a FileProvider such as a react-native-file-provider so that internal files are exposed as contentUri
-
Code changes in RNMailModule.java to check if the
path
is a URI or a file path
import android.webkit.URLUtil;
if (attachment.hasKey("path") && !attachment.isNull("path")) {
String path = attachment.getString("path");
Uri p;
// Check for valid URI
if (URLUtil.isValidUrl(path)) {
p = Uri.parse(path);
}
// Else this is an absolute file path
else {
File file = new File(path);
p = Uri.fromFile(file);
}
i.putExtra(Intent.EXTRA_STREAM, p);
}
Please merge
is this working?
Well... the code above works, but I couldn't get the attachments to Gmail app. I tried using react-native-file-provider and added the provider settings to AndroidManifest.xml, but it just doesn't work (spent a whole day trying to get it to work). It seems that Gmail app only accepts attachments from the external storage area..
I gave up and tried react-native-mail-compose. It works for Android, but the file has to be read as base64 string so I'm using react-native-fetch-blob for it (I already had it in my project).
i need to attach pdf's into the gmail app, so you recommend to use react-native-mail-compose?
Yes! Use it with react-native-fetch-blob so you can read the files as base64 encoded strings out of the box.
https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#readfilepath-encodingpromise
thx so much :D
It worked for me with Gmail
Please merge this!