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

[Error: IOException while sending message] - while using attachments #28

Closed JayM96 closed 4 years ago

JayM96 commented 4 years ago

I am using the following code to implement smtp mail plugin.

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: "test@mail.com",
            password: "jay@1439",
            from: "test@mail.com",
            recipients: "test2@gmail.com",
            subject: "Share item",
            htmlBody: "<h1>Hello Brother</h1><p>How are you? How Do you do?</p>",
            attachmentPaths: [
                RNFS.DocumentDirectoryPath + "/AppName/",
            ],
            attachmentNames: [
                "150420_1458165.jpg",
            ],
            attachmentTypes: ["img", "jpg", "png", "txt"] //needed for android, in ios-only application, leave it empty: attachmentTypes:[]. Generally every img(either jpg, png, jpeg or whatever) file should have "img", and every other file should have its corresponding type.
        }).then(success => {
            console.log("success mail : ", success);
        }).catch(err => {
            console.log("err mail : ", err);
        });

Following is my package.json file :

"dependencies": {
    "@react-native-community/async-storage": "^1.8.1",
    "@react-native-community/masked-view": "^0.1.7",
    "moment": "^2.24.0",
    "native-base": "^2.13.12",
    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-native-axios": "^0.17.1",
    "react-native-barcode-mask": "^1.1.0",
    "react-native-camera": "^3.19.1",
    "react-native-fs": "^2.16.6",
    "react-native-gesture-handler": "^1.6.1",
    "react-native-material-menu": "^1.1.0",
    "react-native-permissions": "^2.0.10",
    "react-native-reanimated": "^1.7.1",
    "react-native-safe-area-context": "^0.7.3",
    "react-native-screens": "^2.4.0",
    "react-native-smtp-mailer": "^1.2.2",
    "react-native-sqlite-storage": "^5.0.0",
    "react-native-svg": "^12.0.3",
    "react-native-swipe-list-view": "^2.5.0",
    "react-native-switch-selector": "^2.0.3",
    "react-native-vector-icons": "^6.6.0",
    "react-navigation": "^4.2.2",
    "react-navigation-drawer": "^2.4.7",
    "react-navigation-stack": "^2.2.3",
    "react-navigation-tabs": "^2.8.7"
  },
  "devDependencies": {
    "@babel/core": "^7.8.7",
    "@babel/runtime": "^7.8.7",
    "@react-native-community/eslint-config": "^0.0.7",
    "babel-jest": "^25.1.0",
    "eslint": "^6.8.0",
    "jest": "^25.1.0",
    "metro-react-native-babel-preset": "^0.58.0",
    "react-native-svg-transformer": "^0.14.3",
    "react-test-renderer": "16.9.0"
  },

Error :

err mail : [Error: IOException while sending message]

Can anyone tell me how to fix it?

Also the path i have used is correct.

Can anyone suggest a solution ?

Thanks.

angelos3lex commented 4 years ago

@JayM96 You need to add the name of the attachment file into the path. So, in your case,

attachmentPaths: [ RNFS.DocumentDirectoryPath + "/AppName/150420_1458165.jpg", ], attachmentNames: [ "this can be whatever, it's the name that will be shown to the file at the recipient's mailbox (works in android only)", ]

JayM96 commented 4 years ago

Yes just did it 5 min ago and it's working now.

Anyway,

Thanks @angelos3lex for replying too fast.