The following is a guest post from Max Katz at Appery.io. Learn more about Max at the bottom of this post.

SendGrid is one of those services that makes adding in-app email capability way too simple. SendGrid is a provider of a cloud-based email solution and provides an elegant and easy-to-use REST API to send emails from a mobile app. It is very likely that your app needs to send emails, such as registration confirmations, password reset emails, two-step verification emails, general notification emails, or any other type of email communication. SendGrid is the perfect solution.

Appery.io, the most complete mobile and web platform offered as a service, enables enterprises to build responsive and mobile apps very fast. Appery.io combines a cloud-based rapid development environment with integrated back-end services and a catalog of API plugins that dramatically simplify integration with cloud services and enterprise systems.

Appery.io’s out-of-the-box integration with any 3rd party API is the perfect match for building messaging-enabled mobile apps fast with the SendGrid API. To make it even faster to add email capability to an app, Appery.io launched a SendGrid Mail API plugin. The plugin can be quickly added to a new or existing app, and provides a sample app that sends an email message with an attachment. The developer can customize or modify the plugin as needed.

In this post, I’m going to show you how to add and use the SendGrid Mail API plugin.

What you’ll need:

Before you start, you’ll need SendGrid and Appery.io accounts. Use the links below to register for free accounts.

What are you going to build?

You are going to create a new mobile app, and add the SendGrid Mail API to send emails. The sample app from the plugin allows you to:

Send an email with an attachment.

Take a picture and include the photo as an attachment.

This is how the app looks when running on an Android device:

You can also check out the video on how to use the SendGrid plugin:

Creating a new mobile app:

The first step is to create a new app in Appery.io:

Once you are inside the platform, click the Create new app button. For app name, enter: SendGridApp (default PhoneApp option selected) and click the Create button.

From the Project view, click on Pages > startScreen. The device screen will open. The page should look like this:

You’ve just created a brand new mobile app. That was easy, right?

Adding the SendGrid plugin:

Now that you have a new app, you are going to add the SendGrid plugin.

1. To import the plugin, click Create New > From Plug-in:

2. In the Communication category, you’ll see the SendGrid Mail API:

3. Click Import selected plugins.

4. You’ll be asked whether you want to set the start page. Go ahead and select mail page. You always change the start page by going to Project>App settings>General.

5. This step is optional, but you can also change the theme used in this app.

a. Go to Project > App settings > General

b. For Theme, select material-design

6. Open Pages > mail page. The page will look like this (using the material-design theme):

The plugin contains a sample app. To test the app, you need to configure the SendGrid API plugin. You are going to do this next, but first, you need to make sure your SendGrid account information is protected.

Setting up a secure proxy:

When you sign up for a SendGrid account you get a username and API key (your password) to use when invoking the API. You want to keep this sensitive information on the server because if someone gains access to this information, they will be able to send emails using your account. The secure proxy will protect this information so it’s never visible in the client.

The first step to creating a secure proxy is to create a database that will store the username and password.

The last step is to configure the service to use this proxy. The plugin has one service, SendGrid_Mail, to send email, so there are just a few things you need to configure:

Inside the App Builder, open Services > SendGrid_Mail service.

For Use Appery.io proxy, click the refresh button to load the new proxy you just created and select it (SendGridProxy).

Switch to the Request tab. This tab contains all the service request parameters. You will also notice that the service will be getting the api_user and api_key from the proxy. The one request parameter you need to set is from. This is your “from” email.

You can modify the service and add more request parameters supported by the SendGrid Mail API.

Besides from (and optional toname and fromname) you don’t need to set the values in the service as they will be mapped from the page. This is how the mapping looks on the page (Pages > mail > Data > sendgrid_email service > Before send mapping):

If you want to learn more about the plugin, modify the sample app, or send an email without an attachment, please read the plugin documentation.

Testing the app:

You are ready to test the app.

1. Click the “Test” button to launch the app in the browser.

a. If you test the app in the browser, you can’t invoke the camera. You can still send a message; a sample image created in Project > JavaScript > SampleImageScript will be sent instead.

2. To use the camera, the fastest way is to use the Appery.io Tester app, or install the app on a device.

This is testing the app on an Android device:

Testing the app in the browser (you can scan the QR code to launch the app on your device in the browser):

What’s next?

In addition to Appery.io App Builder, you also get integrated backend services such as a cloud database, push notifications and server scripts to write custom business logic for the app.

Summary

Building apps with in-app email capability with SendGrid and Appery.io is fast and simple. The SendGrid API plugin can be quickly integrated, tested and secured when building a mobile app in Appery.io.

About the author: Max Katz heads Developer Relations for Appery.io, a cloud-based mobile app platform. He loves trying out new and cool REST APIs in mobile apps. Max is the author of two books “Practical RichFaces” (Apress 2008, 2011), DZone MVB (Most Valuable Blogger), and is a frequent speaker at developer conferences. You can find out what Max is up to on his blog: http://maxkatz.org and Twitter: @maxkatz.