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 a method, addAttachment()
, that accepts a local path of the file we want to attach.
Adding an attachment is usually as simple as passing the addAttachment()
method of the e-mail dialog and the location of the file or blob you wish to attach, for example:
//add an image from the Resource/images directory emailDialog.addAttachment('images/my_test_photo.png');
Our case is a bit trickier than this though. In order to successfully attach our chosen image, we need to first save it temporarily to the file system, and then pass the file system path to addAttachment()
. Alter your postToEmail
function to match the following code:
//create your email function...