Closed kush4999 closed 2 years ago
Your path seems wrong, the path should be relative to the documents directory path of the app, since you use RNFS.DocumentDirectoryPath. Take a look at the paths doc
I had try all the thing but still it gave
err mail : [Error: IOException while sending message] can you please help me and tell where is the problem?
Thank you
What @angelos3lex means is that [RNFS.DocumentDirectoryPath + "F:\Innovius\Demo\Sunflower.jpg"]
builds an incorrect path. This path will look something like "/data/user/0/com.innovius.demo/filesF:\Innovius\Demo\Sunflower.jpg"
, which, by the way, also uses illegal escape sequences.
You need to use relative paths, so it would look like [RNFS.DocumentDirectoryPath + "/Sunflower.jpg"]
. As to how to get your Sunflower in there, that depends on your framework...
RNSmtpMailer.sendMail({ mailhost: "smtp.gmail.com", port: "465", ssl: true, //if ssl: false, TLS is enabled,note: in iOS TLS/SSL is determined automatically, so either true or false is the same username: "happy953singh@gmail.com", password: "qkxukddrbrjdtsqu", from: "abc@gmail.com", recipients: Email, subject: "share image", htmlBody: "
How are you? How Do you do?
", +++++ attachmentPaths: [RNFS.DocumentDirectoryPath + "/DSC_7355.JPG"], attachmentNames: ["DSC_7355.JPG"], attachmentTypes: ["jpg", "png"] }).then(success => { console.log("success mail : ", success); alert("Mail send successfully "); }).catch(err => { console.log("err mail : ", err); alert("Error in send mail "); });as you said i had modify this line but now it wil show differt error like: err mail : [Error: Attempt to invoke virtual method 'int java.lang.String.indexOf(int)' on a null object reference]
so can you please help me what can do in this particular problem .
Thank you
There's only a single instance of .indexOf()
in the entire codebase and that's on recipients
. Looking at your code, it simply says recipients: Email
. It sounds like Email
is simply undefined
or null
, throwing this IOException.
I am using the following code to implement smtp mail plugin.
import React, { Component } from "react"; import { Button, StyleSheet, Text, View } from "react-native"; import RNSmtpMailer from "react-native-smtp-mailer"; import RNFS from "react-native-fs";
export default class App extends Component { sendEmail = () => { RNSmtpMailer.sendMail({ mailhost: "smtp.gmail.com", port: "465", ssl: true, //if ssl: false, TLS is enabled,note: in iOS TLS/SSL is determined automatically, so either true or false is the same username: "happy953singh@gmail.com", password: "qkxukddrbrjdtsqu", from: "abc@gmail.com", recipients: "kush49shah@gmail.com", subject: "share image", htmlBody: "
How are you? How Do you do?
", attachmentPaths: [RNFS.DocumentDirectoryPath + "F:\Innovius\Demo\Sunflower.jpg"], attachmentNames: ["flower.jpg"] attachmentTypes: ["jpg", "png"] }).then(success => { console.log("success mail : ", success); }).catch(err => { console.log("err mail : ", err); }); }render() { return (
} }
const styles = StyleSheet.create({ container: { flex: 1, justifyContent: "center", alignItems: "center", backgroundColor: "#F5FCFF" }, welcome: { fontSize: 20, textAlign: "center", margin: 10 }, instructions: { textAlign: "center", color: "#333333", marginBottom: 5 } });
Following is my package.json file :
{ "name": "Demo", "version": "0.0.1", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "start": "react-native start", "test": "jest", "lint": "eslint ." }, "dependencies": { "@react-native-community/cameraroll": "^4.0.4", "@react-navigation/bottom-tabs": "^5.11.10", "@react-navigation/drawer": "^5.12.5", "@react-navigation/native": "^5.9.4", "@react-navigation/stack": "^5.14.5", "firebase": "^8.5.0", "native-base": "^2.15.2", "nodemailer": "^6.6.0", "radio-buttons-react-native": "^1.0.4", "react": "17.0.1", "react-native": "0.64.1", "react-native-dialogflow": "^3.2.2", "react-native-document-picker": "^5.0.3", "react-native-elements": "^3.4.1", "react-native-email": "^1.1.0", "react-native-fast-image": "^8.3.4", "react-native-fs": "^2.18.0", "react-native-gesture-handler": "^1.10.3", "react-native-gifted-chat": "^0.16.3", "react-native-image-crop-picker": "^0.36.2", "react-native-image-picker": "^3.6.0", "react-native-mail": "^6.1.0", "react-native-mail-compose": "^0.0.6", "react-native-marquee": "^0.3.2", "react-native-modal": "^11.10.0", "react-native-paper": "^4.8.1", "react-native-reanimated": "^2.1.0", "react-native-responsive-screen": "^1.4.2", "react-native-safe-area-context": "^3.2.0", "react-native-screen": "^1.0.1", "react-native-screens": "^3.2.0", "react-native-size-matters": "^0.4.0", "react-native-sms": "^1.11.0", "react-native-smtp-mailer": "^1.2.4", "react-native-splash-screen": "^3.2.0", "react-native-star-rating": "^1.1.0", "react-native-textarea": "^1.0.4", "react-native-unordered-list": "^1.0.4", "react-native-vector-icons": "^8.1.0", "react-native-voice": "^0.3.0", "react-native-webview": "^11.4.4", "react-navigation": "^4.4.4", "react-navigation-drawer": "^2.7.1", "react-navigation-stack": "^2.10.4", "rn-fetch-blob": "^0.12.0" }, "devDependencies": { "@babel/core": "^7.14.0", "@babel/runtime": "^7.14.0", "@react-native-community/eslint-config": "^2.0.0", "babel-jest": "^26.6.3", "eslint": "^7.26.0", "jest": "^26.6.3", "metro-react-native-babel-preset": "^0.66.0", "react-test-renderer": "17.0.1" }, "jest": { "preset": "react-native" } }
Error :
err mail : [Error: IOException while sending message]
I had try all the things but still i get this error Can anyone tell me how to fix it?
Thanks.