Email dialog error

You must Login before you can answer or comment on any questions.

I just want to send an email with a file attachment. But i m getting an error as cannot set property "subject" of null to " Hello from Titanium".

code is : var emailDialog = Titanium.UI.createEmailDialog() emailDialog.subject = "Hello from manu"; emailDialog.toRecipients = ['ranjanmanu@yahoo.com']; emailDialog.messageBody = '<b>U Rock!</b>'; var f = Ti.Filesystem.getFile('cricket.wav'); emailDialog.addAttachment(f); emailDialog.open();

Cant recognise whats the error ...please help me.

thanks

4 Answers

emailDialog.setSubject('Hello from manu');
emailDialog.setMessageBody('U ROCK!');
they have methods to set those, properties aint working.

— answered 2 years ago by Kami -
answer permalink
4 Comments
  • Canu please describe in detail ..thanks

    — commented 2 years ago by Manu ranjan

  • Canu please describe in detail ..thanks

    — commented 2 years ago by Manu ranjan

  • right now you use this

    emailDialog.subject = 'hello from manu';
    this gives an error, telling you 'subject' is not a valid property of emailDialog. It does not excist so it will give you an error.

    the following code is used to set a subject instead of your code

    emailDialog.setSubject('Hello from manu');
    this is a valid method of the emailDialog and will result in no chrash.

    — commented 2 years ago by Kami -

  • Show 1 more comment

o.O , something is wrong...

can you try this code?

var emailDialog = Ti.UI.createEmailDialog();
    emailDialog.toRecipients = ['testmail@text.com'];
    emailDialog.open();
does this work? if not then something is wrong with your SDK

— answered 2 years ago by Kami -
answer permalink
3 Comments
  • Are you saying to try only 3 lines...no message no subject ????

    — commented 2 years ago by Manu ranjan

  • i tried the above lines of code, it gives error as cannot set property " toRecipients" of null to "org.mozilla.javascrit.NativeArray@3e42b8..

    — commented 2 years ago by Manu ranjan

  • you can even create the dialog and open it without setting anything.

    but like matt said, something else is causing your app to crash

    — commented 2 years ago by Kami -

Manu,

It looks like maybe you are having an issue with another part of your code, or your build is messed up. Try clearing out your <project directory>/build/android directory (or if your using titanium studio, click project menu, then clean) If that does not work we might need to see some more of your surrounding code to see what the issue might be.

— answered 2 years ago by Matt Apperson
answer permalink
1 Comment
  • Mark i did clear the directory....so my complete code is this,....please have a look thanks...

    var win = Titanium.UI.currentWindow; win.add(Titanium.UI.createLabel({ text: "", color:'red', font:{fontSize:20,fontFamily:'Helvetica Neue'}, }));

    var alert = Titanium.UI.createAlertDialog({ title: 'Virus Found', message: 'Do you want to delete the Virus', buttonNames: ['Yes', 'No'], cancel: 1 }); alert.addEventListener('click', function(e) { Titanium.API.info('e = ' + JSON.stringify(e)); switch (e.index) { case 0: Titanium.API.info('Clicked button 0 (YES)'); win.add(Titanium.UI.createLabel({ text: "Three Trojan horses deleted", color:'red', font:{fontSize:20,fontFamily:'Helvetica Neue'}, })); break;

      //This will never be reached, if you specified cancel for index 1
      case 1: Titanium.API.info('Clicked button 1 (NO)');
      win.add(Titanium.UI.createLabel({
    text: &quot;As you wish )&quot;,
    color:'red',
    font:{fontSize:20,fontFamily:'Helvetica Neue'},
    

    }));

      default:
      break;
    

    } });

    alert.show();

    var input_2 = Titanium.UI.createTextField({ top: 20, left: 10, width: 200, height: 44 }); win.add(input_2); var button2 = Titanium.UI.createButton( { title : "Alert box", top: 70, left: 10, width: 200, height: 44 } ); win.add(button2); button2.addEventListener( "click", function messageCallback(e){ var alertDialog = Titanium.UI.createAlertDialog({ title: 'Hello', message: 'You got mail' + " " + input_2.value + '.', buttonNames: ['OK','Doh!'] }); alertDialog.show();

    }); var button3 = Titanium.UI.createButton( { title : "To show activity indicator", top: 130, left: 10, width: 200, height: 44 } ); win.add(button3); button3.addEventListener( "click", function messageCallback(e){ var actInd = Titanium.UI.createActivityIndicator({ height:50, width:10 }); actInd.show(); }); var emailDialog = Titanium.UI.createEmailDialog() emailDialog.setSubject('Hello from manu'); emailDialog.toRecipients = ['ranjanmanu@yahoo.com']; emailDialog.setMessageBody('U ROCK!'); var f = Ti.Filesystem.getFile('cricket.wav'); emailDialog.addAttachment(f); emailDialog.open();

    — commented 2 years ago by Manu ranjan

Mark i did clear the directory....so my complete code is this,....please have a look thanks...

var win = Titanium.UI.currentWindow; win.add(Titanium.UI.createLabel({ text: "", color:'red', font:{fontSize:20,fontFamily:'Helvetica Neue'}, }));

var alert = Titanium.UI.createAlertDialog({ title: 'Virus Found', message: 'Do you want to delete the Virus', buttonNames: ['Yes', 'No'], cancel: 1 }); alert.addEventListener('click', function(e) { Titanium.API.info('e = ' + JSON.stringify(e)); switch (e.index) { case 0: Titanium.API.info('Clicked button 0 (YES)'); win.add(Titanium.UI.createLabel({ text: "Three Trojan horses deleted", color:'red', font:{fontSize:20,fontFamily:'Helvetica Neue'}, })); break;

  //This will never be reached, if you specified cancel for index 1
  case 1: Titanium.API.info('Clicked button 1 (NO)');
  win.add(Titanium.UI.createLabel({
text: &quot;As you wish )&quot;,
color:'red',
font:{fontSize:20,fontFamily:'Helvetica Neue'},

}));

  default:
  break;

} });

alert.show();

var input_2 = Titanium.UI.createTextField({ top: 20, left: 10, width: 200, height: 44 }); win.add(input_2); var button2 = Titanium.UI.createButton( { title : "Alert box", top: 70, left: 10, width: 200, height: 44 } ); win.add(button2); button2.addEventListener( "click", function messageCallback(e){ var alertDialog = Titanium.UI.createAlertDialog({ title: 'Hello', message: 'You got mail' + " " + input_2.value + '.', buttonNames: ['OK','Doh!'] }); alertDialog.show();

}); var button3 = Titanium.UI.createButton( { title : "To show activity indicator", top: 130, left: 10, width: 200, height: 44 } ); win.add(button3); button3.addEventListener( "click", function messageCallback(e){ var actInd = Titanium.UI.createActivityIndicator({ height:50, width:10 }); actInd.show();

}); var emailDialog = Titanium.UI.createEmailDialog() ; emailDialog.setSubject('Hello from manu'); emailDialog.toRecipients = ['ranjanmanu@yahoo.com']; emailDialog.setMessageBody('U ROCK!'); var f = Ti.Filesystem.getFile('cricket.wav'); emailDialog.addAttachment(f); emailDialog.open();

— answered 2 years ago by Manu ranjan
answer permalink
3 Comments
  • What Titanium SDK are you using and what android version are you testing with?

    — commented 2 years ago by Matt Apperson

  • Titanium SDK VERSION IS 1.5.1 and 2.1 is the android version.

    — commented 2 years ago by Manu ranjan

  • try downloading titanium SDK version 1.6.2. It could be that 1.5.1 does not have email dialog for android. I dont know if this is the case, but going for 1.6.2 could solve the problem

    also android 2.2 API's is the best version in my experience

    — commented 2 years ago by Kami -

Your Answer

Think you can help? Login to answer this question!