angelos3lex / react-native-smtp-mailer

Send emails by connecting to smtp server+attachments, using android javamail and ios mailcore2
39 stars 32 forks source link

err mail : [Error: IOException while sending message] #44

Closed kush4999 closed 2 years ago

kush4999 commented 3 years ago

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 (

Welcome to Smtp Mailer!
angelos3lex commented 3 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

kush4999 commented 3 years ago

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

Kiruse commented 3 years ago

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...

kush4999 commented 3 years ago

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

Kiruse commented 3 years ago

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.