Hey all, I’ve read the article Velo Tutorial: Sending an Email on Form Submission back and forth, set up everything and am actually getting “success” status after running the code, but I dont recieve any mails. I’m really frustrated since it worked for me couple of months ago. I tried to set up new API key and everything, and store a whole new Secret for it, and it still doesnt work.
I’m attaching my code + my log during the alogrithm running.
The codes are very standard, almost modified nothing, just copy and pasted from the article.
//page code
//event handler for the ‘Send’ button:
export function sendbut1_click(event) {
sendmail(1);
}
function sendmail(index) {
let $sendbut = $w(‘#sendbut’ + index);
let $sentbut = $w(‘#sentbut’ + index);
console.log(“You clicked the send button”)
let email = $w(‘#mail1’).value
console.log(email);
sendFormData(email);
console.log(“mail sent”)
$sendbut.hide();
$sentbut.show();
}
function sendFormData(email) {
const subject = New Submission from BIZIT!
;
const body = HELLO, THIS IS FIRST TEST from: \rHey 1 \rDoes it work?
console.log(“Im now sending the data to the backend”)
sendEmailWithRecipient(subject, body, email)
.then(response => console.log(response));
}
//backend code
export async function sendEmailWithRecipient(subject, body, recipient) {
const sendGridSecret = JSON.parse(await wixSecretsBackend.getSecret(‘recmails1’));
const key = sendGridSecret.key;
const sender = sendGridSecret.senderEmail;
console.log(“Im now sending it from 1st step backend to 2nd step backend”)
return sendWithService(key, sender, recipient, subject, body);
}
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
};
console.log(“2nd step is happening”)
return fetch(url, request)
.then(response => response.json());
}
//end of code
//logs:
Also, as you can see I added “async” to the functions declare since “await” generated error without it, is it fine?
Thanks in advance!