Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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!

— asked July 14th 2010 by Andy Majot
  • android
  • attachment
  • email
  • empty
  • file
  • mobile
0 Comments

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??

    — answered August 22nd 2011 by Luis Cañamares
    permalink
    1 Comment
    • I am trying to add the "Download from Android Marketplace" logo and link to the end of an email I am sending from an app. How can I insert the image in the messageBody?

      I guess I can add HTML code with an <a> tag, but I dont want to limit it to HTML only email clients.

      Any ideas anyone?

      Thanks!

      — commented December 13th 2011 by Sridevi Kolluri
  • 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?

    — answered February 8th 2012 by Kouroche Sedaghatian
    permalink
    1 Comment
    • So it looks like regardless of the attachment type, the size and type are as I mentioned above (0 and message/rfc822 respectively). But still I can attach an image file, but a text file always comes across as a 0 byte file with nothing in it.

      To boot, looks like once an email has been fired, the second email never really goes through even though you get a notification about sending email :)

      — commented February 8th 2012 by Kouroche Sedaghatian
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.