Cloud Code Functions
Integrations

SendGrid

11min

Using Sendgrid email API

Introduction

This section explains how you can integrate SendGrid with a Cloud Code function. After completing this guide with step-by-step instructions, you will be ready to use your function in your App and call it at your iOS or Android App.

Prerequisites

To complete this tutorial, you will need:

Let’s get started!

We will write a function using SendGrid that you will be able to work with a lot from possibilities as Delivering messages to our customers and configuring parameters to use the SendGrid v3 REST API.

To learn how to create or access an Account in SendGrid, check the links given below:

1 - Create a SendGrid API Key

The most important step before start to code is create the correct keys to setup your environment. After accessing your account, locate in the Settings drop-down menu, the API Keys option as in the picture below:

Document image


After that, at the top right locate and choose an identification to theAPI Key Name, like as shown below:

Document image


As you can see at the image above, it’s necessary to select one option to allow the Full Access to the API Key.

After click on the Create & View to proceed with creating of the key, you will be able to see the screen below:

Document image


Hint: Be careful to write it down, as there is no way to retrieve it. Click on the text to copy it.

2 - Add a function to the Cloud Code

The main strategy to this way of using SendGrid’s API is to create a function on the Cloud Code named sendgridEmail and call it from the App.

2.1 - Install module from Sendgrid

Create a file called package.json, and inside this file, you need to install the Twilio module, like:

JSON


2.2 - Implement Cloud Code

You should note that every email field has to be send by the App – from the subject to the content – as a parameters. The code is as follows:

Parse Server 3.X
Parse Server 2.X


Hint: Remember to change the fields from and reply_to to your personal information.

Then it is necessary to implement a call to the Cloud Code function on the app.

3 - Call Cloud Code function

In this current step, we can work with two possibilities to call our function, they’re: Android and iOS (Swift and Objective-C).

Android
iOS(Swift)
iOS(Objective-C)


4 - It’s done!

And that’s it for the SendGrid usage. Note that you might want to use some sort of authentication before allowing anyone to use your SendGrid API to send emails.

In case you need any help or a function/link doesn’t work, please contact our team via chat!

Updated 28 Mar 2024
Did this page help you?