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

Attachement is not working #28

Closed
avneet007 opened this issue Mar 27, 2014 · 10 comments
Closed

Attachement is not working #28

avneet007 opened this issue Mar 27, 2014 · 10 comments

Comments

@avneet007
Copy link

Hello
i am using this plugin for jquerymobile+phonegap for IOS. while i am sending the image data as attachment as base 64 string() as you showed in the examples..
window.plugin.email.open({
subject: 'Cordova Icon',
attachments: ['base64:icon.png//iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAYAAAA6/...']
});

it show me the encoded attachment on the device. and while receiving its not showing anything at all.

Thanks
Avneet

@tbh726
Copy link

tbh726 commented Mar 27, 2014

I am also not getting the attachment.. it show an icon of a "pdf" in the window it opens. this is what i am doing.., it does send the email without an attachment fine.

var canvas = document.getElementById('myCanvas')

var imageData = canvas.toDataURL()
console.log(imageData);

window.plugin.email.open({
                         to:      ['blahblah@gmail.com'],
                         attachments: [imageData],
                         subject: 'SnapShot',
                         body:    'How are you? Nice greetings from Leipzig'
                         });

@avneet007
Copy link
Author

Hello
Is there any one who can help me on this. ? i tried to add html in the body with
' where img is a base64 string. it showing me good on the email composer in Ipad but at receiving end nothing is there.??

@miguelwicht
Copy link

The pdf icon in the mail composer doesn't mean, that the attachment is actually working! iOS seems to add an empty attachment as long as there is a file name with an extension it knows. If you are using an image or a pdf there should be an actual preview of it if it's working.

@avneet007
Copy link
Author

Hello

Any answer of my question i am adding simple html in the body and set the html attribute to true also. it showing me that attachment fine in the iPad but at the receiving end its not showing anything event not that html.

note:- using Google account in the iPad for sending the email.

Thanks
Avneet

@katzer
Copy link
Owner

katzer commented Mar 31, 2014

... I am busy at the moment :(

@ericcmmi
Copy link

ericcmmi commented Apr 1, 2014

I've been trying to get it to work on Android and it appears to be a problem with the storage path. I've replaced a couple of lines in EmailComposer.java with a path that works on my test phone and verified that it does work but this is not a final solution since I'm creating the folder manually and I'm not sure this will work on other phones. This is my first try at modifying an Cordova plugin so I will keep working on it and if I come up with a good solution I will post it. I'm going to look at the iOS side also.

    } else if (path.startsWith("base64:")) {
        String resName = path.substring(path.indexOf(":") + 1, path.indexOf("//"));
        String resData = path.substring(path.indexOf("//") +2);

    byte[] bytes   = Base64.decode(resData, 0);

        //String storage = this.cordova.getActivity().getCacheDir() + "/email_composer";
    String storage = "/storage/sdcard0/Android/data/de.appplant.cordova.plugin/email_composer";

        File file = new File(storage, resName);

    new File(storage).mkdir();

        try {
            FileOutputStream os = new FileOutputStream(file, true);

            os.write(bytes);
            os.flush();
            os.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        //return Uri.parse("content://" + AttachmentProvider.AUTHORITY + "/" + resName);
    return Uri.parse("file://" + storage + "/" + resName);
    }

@ericcmmi
Copy link

ericcmmi commented Apr 1, 2014

Let me be a little more specific. The code

this.cordova.getActivity().getCacheDir() + "/email_composer"

returns the following for my app (PolicyHolderServices)

/data/data/com.fmins.policyholderservices/cache/email_composer

and

"content://" + AttachmentProvider.AUTHORITY

returns

content://de.appplant.cordova.plugin.emailcomposer.attachmentprovider

So there seems to be a mismatch between the path being used to create the temporary file for the attachment and the path being used to retrieve it.

@ericcmmi
Copy link

ericcmmi commented Apr 1, 2014

Here's what I'm going with for Android. It requires external storage but so do some of the other options in the email composer. I borrowed a little bit from the relative section and also from the following SO article. Now onto iOS.

http://stackoverflow.com/questions/3570914/android-how-do-i-attach-a-temporary-generated-image-to-an-email

    } else if (path.startsWith("base64:")) {
        String resName = path.substring(path.indexOf(":") + 1, path.indexOf("//"));
        String resData = path.substring(path.indexOf("//") +2);

        byte[] bytes   = Base64.decode(resData, 0);

        File imageDir = new File(
            Environment.getExternalStorageDirectory(),   
            "/Android/data/" + this.cordova.getActivity().getPackageName() + "/email_composer");

        if (!imageDir.exists()) {
            imageDir.mkdirs();
        }

        File file = new File(imageDir, resName);

        try {
            FileOutputStream os = new FileOutputStream(file, true);

            os.write(bytes);
            os.flush();
            os.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return Uri.fromFile(file);
    }

@avneet007
Copy link
Author

Hello
any update regarding sending the html data in body ??

@katzer
Copy link
Owner

katzer commented Apr 6, 2014

Hello,

both relative:// and base64:// had an error, which have been fixed now (missing permission and wrong dir path).

@katzer katzer closed this as completed Apr 6, 2014
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

5 participants