The following is a guest blog post from Sidney Maestre, a Platform Evangelist for StackMob, a leading provider of backend services for mobile developers. He spent the last few years building mobile apps and sharing his knowledge with others. These efforts included speaking at Adobe MAX, 360iDev, SenchaCon, HTML5DevConf, Silicon Valley Code Camp, creating two courses, jQuery Mobile for Beginners and Learn Backbone.js + StackMob, for the uDemy.com platform and organizing the Bay Area Mobile meetup. Follow him on Twitter and Github at @SidneyAllen.
Building backend services for a mobile app is time consuming and difficult. Adding a datastore API, push notifications and user authentication can eat up 25 to 40 percent of development time. That’s why many mobile developers turn to StackMob to help them build a backend in minutes not months.
StackMob provides a cloud-based backend for mobile app developers that incorporates BaaS (backend as a service) features to enable rapid creation of CRUD (create, read, update and delete) APIs for mobile apps. StackMob simplifies file upload and storage to Amazon S3, user management and user authentication through Facebook and Twitter. They also support two of the most popular cloud services among mobile developers push notifications and geo location services.
StackMob supports custom-code enabling mobile developers to write business logic and go beyond what is possible with a traditional datastore API. With the introduction of HTTPService support in custom code, you can now call third-party APIs over HTTP. This article shows how you can leverage email infrastructure service provider SendGrid. SendGrid is a cloud-based service that replaces your company’s email infrastructure and provides everything you need to operate a reliable and scalable outbound email delivery system. For more information about SendGrid, check out their API documentation.
We’ll review how to create a StackMob application, modify the user schema to add an email and name field and add a new user via the StackMob dashboard. Next we’ll download the example custom code, add our SendGrid credentials and compile and upload the code to StackMob. Lastly, we’ll download and configure an XCode project and run it in the simulator to send a custom email message for our user.
You’ll need a StackMob account, so if you haven’t already signup for your free StackMob account now.
After you sign up, you’ll be taken to our getting started page. Give your application a name and click the create application button. I’m calling my “sendgrid”, you can call it anything you want. You have the option to select a platform and download the StackMob SDK, but for this article we provide you with an XCode project with the SDK already install, so you can skip this step. At the top of the page click on dashboard.

Every application created on StackMob includes a User schema with a username and password. Let’s add an email address and name field to the User schema. In the dashboard, click on Manage Schemas link on the left.

Click the edit link next to the User schema.

Click the add field button and add the email field with a data type string. Repeat this step to add a field called name. You’ll want to name the field “email” and “name”, since that’s how I refer to them in the SendGrid code for this article.

Remember to click the SAVE SCHEMA button to save your changes.
Click the object browser link on the left side and click add object on the user schema. Enter your username, password, email and name for your user.

Download the StackMob custom-code examples from Github. You’ll find the SendGrid sample code in /Java/src/main/java/com/stackmob/examples/SendGrid.java.
You’ll need a SendGrid account to make the API call, so if you haven’t already signup for your SendGrid account now.
Enter your SendGrid username and password into the SendGrid.java file
The first part of the ResponseToProcess method we parse the JSON object sent from our mobile app, then query the StackMob datastore with the username that is passed. Once we find a match, we can use the name and email address for our SendGrid email.
Then, we’ll build our SendGrid URL and POST it to SendGrid.
Go to Manage App Info in the StackMob Dashboard and copy the Development Public Key. You’ll be pasting it into the AppDelegate.m file in the XCode project.
You’ll download a project with the StackMob SDK installed and setup to pass a username, subject and email text to the custom method.
Inside the XCode project, open the AppDelegate.m file. You’ll update the StackMob client init with the Development Public Key.
Run the project in the iOS Simulator. Enter the username of the User you created on StackMob and click send email button. You should get your email shortly.
If you have feedback or questions please contact me at [email protected].
Danny Randa has been working in digital marketing since the launch of Nickelodeon's virtual world Nicktropolis in 2006. After three years of managing interactive marketing campaigns for Nickelodeon's game, he completed an MBA in Entrepreneurship and Marketing at the Leeds School of Business in Boulder, CO. He now works at SendGrid helping developers solve their email infrastructure challenges.
Daniel Randa on Twitter
That code isn’t correct. The URL encoding won’t work correctly.
You should build the query like
String queryParams = “api_user=” + API_USER + “&api_key=” + API_KEY + “&to=” + username + “&subject=” + URLEncode.encode(title, “UTF-8″) + “&html=” + URLEncode.encode(text, “UTF-8″) + “&from=” + SENDER_EMAIL;
String url = “htt……,com/mail.send.json?” + queryParams;
If not done like that, some params won’t be enconded properly
Hi Alvaro,
Thanks for catching that. I was URI encoding, but I've changed it to URLEncoding parameters. I've updated the github repository.