Adding attachments to an e-mail
Now we have a basic e-mail dialog up and running, but ideally what we want to do is attach the photo that we selected from our Photo Gallery to our new e-mail message. Luckily for us, Titanium makes this easy by exposing the Ti.UI.createEmailDialog()
method, which accepts the local path of the file we want to attach.
How to do it...
Adding an attachment is usually as simple as passing the location of the file or blob you wish to attach to the addAttachment()
method of emailDialog
. For example:
//add an image from the Resource/images directory emailDialog.addAttachment(Ti.Filesystem.getFile('/images/my_test_photo.jpg'));
Our case is a bit trickier than this, though. In order to successfully attach our chosen image, we have to first save it temporarily to the file system and then pass the file system path to addAttachment()
. Alter the postToEmail
function to match the following code:
//create your email function postToEmail() { var newDir = Ti.Filesystem.getFile...