Example: Send email with the SendGrid REST interface.

Hi Yisrael-

Is there anything else that needs to be set up behind the scenes to make this work that isn’t immediately obvious? I copied and pasted the backend files from the original tutorial and changed out the key. When I first started and tested, I was able to send 3 emails when I submitted the form without issue. Then, it stopped working. I reached out to sendgrid and they recommended that I setup sender authentication, which I did. They say everything looks good on their end. I’m still not having any luck. I’ve gone through the code line by line and don’t see anything (although that doesn’t mean I didn’t miss something). I’ll post the code below this. Just didn’t know if you’d encountered anything (a setting or permission or otherwise) with wix, sendgrid, or the email provider (g suite in my case) that needs to be accounted for.
Thanks.

// Filename: backend/email.jsw (web modules need to have a .jsw extension)

import {sendWithService} from “backend/sendGrid”;

//export function sendEmail(subject, body, recipient) {
export function sendEmail(subject, body) {
const key = “SG.xxxxxxxxxxxxxxxxxxxxxxxxxxx”;
const sender = “springsworx@gmail.com”;
const recipient = “springsworx@gmail.com”;
return sendWithService(key, sender, recipient, subject, body);
}

//sendGrid.js

import {fetch} from ‘wix-fetch’;

export function sendWithService(key, sender, recipient, subject, body) {
const url = “https://api.sendgrid.com/api/mail.send.json”;

const headers = {
“Authorization”: "Bearer " + key,
“Content-Type”: “application/x-www-form-urlencoded”
};

const data = ‘from=${sender}&to=${recipient}&subject=${subject}&text=${body}’;

const request = {
“method”: “post”,
“headers”: headers,
“body”: data
};

return fetch(url, request)
.then(response => response.json());
}

//email test page
import wixLocation from “wix-location”;
import wixData from “wix-data”;
import {sendEmail} from “backend/email”;

$w.onReady( function () {
//TODO: write your page related code here…

});

function sendFormData() {
const subject = “Test”;
const body = “Thanks”;

//sendEmail(subject, body, address)
sendEmail(subject, body)
.then(response => console.log(response));
}

export function button1_click(event) {
//Add your code for this event here:

sendFormData();
}