SendGrid
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.
To complete this tutorial, you will need:
- An app created at Back4App.
- Back4App Command Line Configured with the project.
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:
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:
After that, at the top right locate and choose an identification to theAPI Key Name, like as shown below:
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:
Hint: Be careful to write it down, as there is no way to retrieve it. Click on the text to copy it.
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.
Create a file called package.json, and inside this file, you need to install the Twilio module, like:
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:
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.
In this current step, we can work with two possibilities to call our function, they’re: Android and iOS (Swift and Objective-C).
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!