OK. I fixed a few things that were wrong and changed my back end function to handle a sender address as well as a recipient address being passed (sendgrid.js remained the same). I’m still not getting any emai l going through. I even generated a new API-Key at SendGrid, but that didn’t help either.
Back end:
//email.jsw
export function sendEmailWithRecipientAndSender(subject, body, recipient, sender) {
const key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
return sendWithService(key, sender, recipient, subject, body);
}
On the page:
// libraries that we need
import wixData from 'wix-data'; // Used to query database
import wixUsers from 'wix-users'; // Used to get the current user
import {sendEmailWithRecipientAndSender} from 'backend/email';
// ...Left out function here that fills read only fields...
// Check that they don't have empty subject and message and send
export function button1_click() {
if (($w('#input3').value !== "") && ($w('#textBox1').value !== "")){
sendMsgData;
$w('#input3').value = "";
$w('#textBox1').value = "Message Sent";
}
else{
$w('#input3').value = "Subject Required!";
$w('#textBox1').value = "Message Required!";
}
}
function sendMsgData() {
let user = wixUsers.currentUser;
let userId = user.id;
wixData.query("Test")
.eq('_id', userId)
.find()
.then( (results) => {
const sender = results.items[0].email;
const recipient = results.items[0].sendEmail;
const subject = `New Mesage from ${$w("#input3").value}`;
const body = `Name: ${$w("#input1").value}
\rEmail: ${$w("#input2").value}
\rMessage: ${$w("#textBox1").value}`;
sendEmailWithRecipientAndSender(subject, body, recipient, sender)
.then(response => console.log(response));
});
}
I tested to make sure that I indeed had values in the parameters that I was passing. I did, and they look valid. Is there something inherently wrong in how I am “calling” SendGrid?