Sending emails through Appcelerator Cloud API

How to send emails from a Titanium application by using the Appcelerator Cloud Services.

This tutorial demonstrates how to use the Cloud API in Titanium Mobile. Specifically, the demo project will allow you to send a template based email to any recipient.

Download source files


This tutorial assumes that you are running Titanium Studio and have the latest SDK updates installed, which was 3.2.0 at the time of this writing.

Step 1: Creating a New Project

In Studio, select File > New Mobile Project.

  1. Select the Classic > Single Window Applications template and click Next.
  2. On the Project Location screen, enter acs-email for the Project name and com.your-domain.acsemail. Replace your-domain with your personal or organization’s domain. Leave the other fields at their default values.
  3. Check the “Cloud-enable this application” option.
  4. Click OK.

The new project opens in Studio.

Step 2: Creating the User Interface

Edit the FirstView, which is located within the FirstView.js file under the “Resources/ui/common” folder. Delete any existing content and replace it with that in the following link:

FirstView source code

Step 3: Configuring the Cloud Service

Before we start with the configuration of Cloud part of this application please keep note of the highlighted code:

The code above sends an email by calling the send() method of ACS Email service. It also makes use of an email template named “default”.

Login to App Console

Log in to your Appcelerator App Console, locate the “acsemail” app and click on the “Manage ACS” link

Create an email template

Visit the “Email Templates” tab and create a new email named “default”.

Please note that the “Development” mode should be selected.

In the body of your email add two variables named {{foo}} and {{bar}}. We will use them in our code in order to inject actual values in the body of the email.

Set the SMTP Settings

Visit the “Settings” tab and configure the SMTP server through which the emails will be sent.

In this example we are using an email account but any other SMTP server can be used.

Step 4: Sending actual content

Our application communicates with the ACS Email template by using the Cloud.Emails.send() method. This method calls a particular Email Templates, sets the recipient and passes additional values by using a JSON structure.

In our example we named our template “default” and prepared in its body two placeholders in order to inject there our actual values.

The following screen capture demonstrates the connection between them

Step 5: Test our application

At this point we are ready to run our application and click on the “Send Email” button.

An email like the following should be received.

Enjoyed this Post?

Follow us on Twitter, or Google+ or even check our Titanium App Templates


Titanium.Cloud.Email API, Cloud Emails API, Source code of this tutorial

/Stavros Kounis,