/* Call pickDocAndSendToMail function on button click */ //...other imports import DocumentPicker from 'react-native-document-picker'; import Mailer from 'react-native-mail'; import RNFS from 'react-native-fs'; pickDocAndSendToMail = async () => { try { const res = await DocumentPicker.pick({ type: [DocumentPicker.types.pdf], }); console.log('document picker response is: ', res); let path = res.uri; if (Platform.OS !== 'ios') { try { let hasPermission = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE); if (!hasPermission) { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE ); hasPermission = granted !== PermissionsAndroid.RESULTS.GRANTED; } if (!hasPermission) { console.log('permission denied'); return; } } catch (error) { console.warn(error); } path = `${RNFS.ExternalStorageDirectoryPath}/project_overview_${Number(new Date())}.pdf`; try { await RNFS.copyFile(res.uri, path); } catch (error) { console.log('file copy error: ', error); return; } } Mailer.mail({ subject: 'need help', recipients: [], body: 'A Bold Body', isHTML: true, attachment: { path, // The absolute path of the file from which to read data. type: 'pdf', // Mime Type: jpg, png, doc, ppt, html, pdf, csv name: 'project_overview.pdf', // Optional: Custom filename for attachment } }, (error, event) => { if (error) { console.log('mailer error: ', error); } }); } catch (err) { if (DocumentPicker.isCancel(err)) { // User cancelled the picker, exit any dialogs or menus and move on } else { throw err; } } }; //...other code