Mobile email sending empty attachment
Hello,
I'm generating an html file that has data in it. I am then attempting to email that html file as an attachment. It looks like everything is added correctly and even sends correctly, but when I email it the recipient gets an attachment with 0 bytes and the file is completely empty.
I can create a web view and point it at the generated file and it displays perfectly fine.
Here is the code:
var newDir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'generated');
newDir.createDirectory();
var htmlFile = Titanium.Filesystem.getFile(newDir.nativePath,'generated.html');
var emailContent = "This is a test of several Android features.";
var contents = "<HTML><HEAD><TITLE>Temporary HTML Test File</TITLE></HEAD><BODY>"+emailContent+"</BODY></HTML>";
htmlFile.write(contents);
var emailDialog = Titanium.UI.createEmailDialog();
emailDialog.subject = "Hello from Android!";
emailDialog.toRecipients = ['#######'];
emailDialog.messageBody = 'You have been sent an email from Android. Please see attachement';
var f = Ti.Filesystem.getFile(newDir.nativePath+'/generated.html');
emailDialog.addAttachment(f); //also tried simply attaching htmlFile
emailDialog.open();
/*
var webview = Ti.UI.createWebView({height:'auto',width:'auto', url:newDir.nativePath+'/generated.html'});
var window = Titanium.UI.createWindow();
window.add(webview);
window.open({modal:true});
*/
the commented code at the bottom works perfectly fine. Does this haves something to do with mimetype? I have also tried this code :
var emailDialog = Titanium.UI.createEmailDialog();
emailDialog.subject = "Hello from Android!";
emailDialog.toRecipients = ['#####'];
emailDialog.messageBody = 'You have been sent an email from Android. Please see attachement';
var f = Ti.Filesystem.getFile(newDir.nativePath+'/generated.html');
emailDialog.addAttachment({mimeType:'text/html', file:newDir.nativePath+'/generated.html'});
emailDialog.open();
Andy help would be appreciated!
2 Answers
-
I have a similar problem… i attach an Image to the email… and it work on IPhone… but not on android… It shows an attachment, but when someone gets the email, it's empty…
Here is my code:
var correo = Ti.UI.createEmailDialog(); correo.subject = "TEST"; correo.addAttachment(Imaview.toBlob());//I have the image loaded in an ImageView before, and it's shown in the screen, so i know that the image exist and that it's there... correo.toRecipients = []; correo.messageBody = 'TEST 2'; correo.open();
Any solution??
-
Running into this issue as well.
I write out a text file and its over 1K in size, but when it gets attached, I see the log say that its size is 0 (Gmail log message). The attachment type is also set to message/rfc822 for some reason.
I think it has to do something with the file type, since attaching an image file works just fine. How can I directly override the contentType for the attachment or the file when I create it?