How to create a web service to send emails for you Android, iOS or web application

No comments
Since it's a common task to have to send emails from your app, this post outlines the quickest way to get a mail service up and running  using server side JavaScript, Parse and Mandrill. No JavaScript or web coding experience is needed.

Set up Parse

1. Go to and create a cloud code app following the process
2. Download
3. Extract the zip
4. Run parse console
5. cd into your working directory
6. run the command parse new <name-of-project>
7. make changes to your code if you like
8. run the command parse deploy

Set up Mandrill

Mandrill is a is an email infrastructure service by MailChimp. It's free to use up to a limit of 12,000 emails per month (and 250 per hour) and it's easy to set up.
Head over to and sign up to get an API key.

The Code

Inside your new Parse project, there should be a folder called cloud, cd into that and create a file called main.js (if it doesn't already exist).
Paste the following code into cloud/main.js

Parse.Cloud.define("sendMail", function(request, response) {
    var Mandrill = require('mandrill');
        message: {
            text: request.params.text,
            subject: request.params.subject,
            from_email: request.params.fromEmail,
            from_name: request.params.fromName,
            to: [{
                email: request.params.toEmail,
                name: request.params.toName
        async: true
    }, {
        success: function(httpResponse) {
            response.success("Email sent!");
        error: function(httpResponse) {
            response.error("ERROR - mail failed to send");

And change the <api key> to your Mandrill API key (obviously withoiut the pointy brackets)
Once this id done, run parse deploy to push your work to parse.

Calling your service

Below is all the paramaters you'll need to send emails from your application.

URL Parameter Key
Raw JSON body:
   "toName":"jane doe",
   "fromName":"john smith",
   "text":"this is the email body for the main message",
   "subject":"this is the email subject"

You will probably want to test this out before you include it in your app. A good way to do this is to use the PostMan client availible free on the Chrome store (similar versions will be out there for Firefox and Safari). 

Fill in the form so that it looks like the image below, and you should see your new email service working :)

No comments :

Post a Comment