Web modules - server-side (backend) code
Accessing 3rd Party Services (using backend function)
Required for this example
The live demo of this example has an additional field for the your SendGrid API Key. To run the live demo, paste your API Key into the SendGrid API Key input field before clicking the Send Email button.
Links for this example
About this example
This example demonstrates how to send an email using the popular 3rd party email processing service SendGrid. We start by setting up a simple form with all of the fields necessary to send an email. When the user completes the form, the user clicks the Send button to request that the email be sent. The fields are checked for validity, and if everything is OK, a post request is sent to SendGrid using fetch(). A Lightbox opens to notify the user of the email’s transmission status (success or failure).
Sending an email using the SendGrid REST API involves using a backend web module and the wix-fetch API to call SendGrid. When clicking the Send Email button, the sendEmail web method (exported from the sendEmail web module, located in the Backend folder) is called. The sendEmail module uses the sendGrid module to perform the actual call to the SendGrid REST API via the wix-fetch HTTP API. Note that you can replace the SendGrid API with any other Email API by providing a replacement for the sendGrid.js file.
For more information, see the tutorial How to Send an Email on Form Submission