Skip to content

Instantly share code, notes, and snippets.

@dawsontoth
Created February 17, 2011 17:15
Show Gist options
  • Save dawsontoth/832158 to your computer and use it in GitHub Desktop.
Save dawsontoth/832158 to your computer and use it in GitHub Desktop.
How to send emails in Appcelerator Titanium using activities and intents.
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
var button = Ti.UI.createButton({ title: 'Share' });
win.add(button);
win.open();
button.addEventListener('click', function() {
var intent = Ti.Android.createIntent({
action: Ti.Android.ACTION_SEND,
type: 'text/plain'
});
intent.putExtra(Ti.Android.EXTRA_SUBJECT, 'My subject!');
intent.putExtra(Ti.Android.EXTRA_TEXT, 'My text!');
try {
Ti.Android.currentActivity.startActivity(intent);
} catch (ex) {
/* Handle Exception if no suitable apps installed */
Ti.UI.createNotification({ message : 'No sharing apps installed!' }).show();
}
});
@rbjack66
Copy link

Dawson,

How would you populate the recipient and CC fields? I tried intent.putExtra(Ti.Android.EXTRA_EMAIL,'username@comcast.net'), but it's not working.

@dawsontoth
Copy link
Author

Let me Google that for you, and click "I'm feeling lucky": "android recipient EXTRA_EMAIL not working"

http://stackoverflow.com/questions/9097080/intent-extra-email-not-populating-the-to-field

"EXTRA_EMAIL" requires an array. Not a single string.

@rbjack66
Copy link

rbjack66 commented Apr 18, 2012 via email

@rbjack66
Copy link

Unfortunately that didn't work either under Appcelerator

@dawsontoth
Copy link
Author

Well that's excruciating. Mind creating a ticket so we can address whatever issue is preventing it from working? https://jira.appcelerator.org/secure/CreateIssue.jspa?pid=10190&issuetype=1&Create=Create

@rbjack66
Copy link

rbjack66 commented Apr 18, 2012 via email

@aniruddhasm
Copy link

This is the solution

var activity = Ti.Android.currentActivity;
var intent = Ti.Android.createIntent({
       action: Ti.Android.ACTION_SEND,
       type: 'text/email'
});
intent.putExtra(Ti.Android.EXTRA_EMAIL, ["to@email.com"]);
intent.putExtra(Ti.Android.EXTRA_SUBJECT, "email subject");
intent.putExtra(Ti.Android.EXTRA_TEXT, "email body /message ");
activity.startActivity(intent, 'Email');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment