Closed avneet007 closed 10 years ago
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'
});
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.??
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.
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
... I am busy at the moment :(
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);
}
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.
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.
} 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);
}
Hello any update regarding sending the html data in body ??
Hello,
both relative:// and base64:// had an error, which have been fixed now (missing permission and wrong dir path).
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