Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Struggeling with android attachments #29

Open
maendamedia opened this issue Apr 21, 2020 · 7 comments
Open

Struggeling with android attachments #29

maendamedia opened this issue Apr 21, 2020 · 7 comments

Comments

@maendamedia
Copy link

Hello,

Like your module and iOS works great.
For android it is not so easy :)

I let the user select some images using the react-native-image-crop module and store them in an array.
This array will be filtered and attached tot the smtp email .

As mentioned, iOS works great, but on android i get the famous IOExeption.

What am i doing wrong here:

const attachmentPaths = [];
    const attachmentNames = [];
    const attachmentTypes = [];
    var re = /(?:\.([^.]+))?$/;

    for (var i = 0; i < image1.length; i++) {
      let filePath = image1[i].path;
      let fileName = filePath.substring(filePath.lastIndexOf('/') + 1);

      attachmentPaths[i] = filePath;
      if (Platform.OS === 'android') {
        attachmentNames[i] = fileName;
        attachmentTypes[i] = re.exec(filePath)[1];
        console.log(attachmentTypes);
      }
    }

    RNSmtpMailer.sendMail({
      mailhost: cs.mailServerHost,
      port: cs.mailServerPort,
      username: cs.mailServerUserName,
      ssl: true,
      password: cs.mailServerPassword,
      from: 'myactualemail',
      recipients: 'receipt emaill',
      bcc: ['bccemail address'],
      subject: 'E-mail vfrom app app',
      htmlBody: `my html text`,
      **attachmentPaths: attachmentPaths,**
      **attachmentNames: attachmentNames,** //only used in android, these are renames of original files. in ios filenames will be same as specified in path. In ios-only application, leave it empty: attachmentNames:[]
      attachmentTypes: attachmentTypes, //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 => {alert(success)} ......rest of code
@angelos3lex
Copy link
Owner

@maendamedia Unfortunately this lib doesn't yet support loading attachments that are not in the filesystem of the device. The crop library you are using, has a writeTempFile (ios only) option that you are probably using, but works only on ios. So in android, there is no tmp file in the filesystem, and it can't be loaded. A workaround, will be to save the file yourself in a tmp folder, and then load it with this library.

@LuizFBrisighello
Copy link

LuizFBrisighello commented May 6, 2020

@angelos3lex Just like @maendamedia, Im using react-native-image-crop to take a photo, after that I save the img using @react-native-community/cameraroll and then I call smtp but I get this error IOException while sending message

I guess it relates to #23

The path that is returned from saving the photo to the library is: content://media/external_primary/images/media/9624

My code:

            ImagePicker.openCamera({
              width: 300),
              height: 400)
            }).then(image => {
              console.log(image)
              CameraRoll.saveToCameraRoll(image.path).then(path => {
                console.log(path)
                    RNSmtpMailer.sendMail({
                        mailhost: 'email-smtp.us-east-1.amazonaws.com',
                        port: '587',
                        ssl: false,
                        username: 'host.userName',
                        password: 'host.password',
                        from: '[email protected]',
                        recipients: '[email protected]',
                        subject: service,
                        htmlBody: '<p>body</p>',
                        attachmentPaths: [path + '.jpg'],
                        attachmentNames: ['image.jpg'],
                        attachmentTypes: ['img']
            })
            .then(success => {
                if (step === curStep) {
                console.log(success)
                dispatch(nextStep())
                alert(success)
        }
      })
      .catch(err => console.log(err))
              })
            }).catch(error => { console.log(error) })

Am I missing something here?

@angelos3lex
Copy link
Owner

Why do you append .jpg on the path and you don't trust exactly what the camera-roll lib returns? Could you try that as well?

@LuizFBrisighello
Copy link

LuizFBrisighello commented May 6, 2020

@angelos3lex The outcome is the same, I thought because camera-roll's path doesnt specify file type it would fail. I'll try react-native-fs and get back to you

@yasirwahid
Copy link

yasirwahid commented May 18, 2020

@angelos3lex @LuizFBrisighello im having the same issue with android. showing me IOexception while ios is working fine any leads?
the path is correct . im picking an image from gallery through react-native-image-picker, not working with camera either.

@LuizFBrisighello
Copy link

@yasirwahid I ended up moving to other tasks without solving the attachments issue. react-native-fs doesnt do the right behaviour for me..

@angelos3lex
Copy link
Owner

Could you guys check if the solution proposed by samuelj1323 in #23 is the reason behind this prob?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants