Hi there,
I am struggling a bit in understanding why the follow codes do not work. After reading about personalisation of SendGrid api and reading the v3 blog post on https://www.wix.com/corvid/forum/community-discussion/sending-template-emails-with-sendgrid-v3 , I updated some of the codes I’ve been using for the following:
Backend: sendGrid.js
export function sendWithService(key, sender, recipient, cc, subject, body) {
const url = “https://api.sendgrid.com/v3/mail/send”;
const MyHeaders = {
“Authorization”: "Bearer " + key,
“Content-Type”: “application/json”
};
const MyBody = {
“personalizations”: [{
“to”: recipient,
“from”: {
“email”: sender
},
“subject”: subject,
“content”: [{
“type”: “text/html”,
“value”: body
}]
};
return fetch(url, {
“method”: “POST”,
“headers”: MyHeaders,
“body”: JSON.stringify(MyBody)
})
.then(Response => Response.text);
}
Backend: email.jsw
export function sendEmailToPeople(sender, recipient, cc, subject, body) {
const key = “xxxxxx(mykey)”;
return sendWithService(key, sender, recipient, cc, subject, body);
}
Front end:
$w(‘#send’).onClick(()=>{
let recipient = [{
“email":"example1@gmail.com”
},
{
“email":"example2@gmail.com”
}]
let sender = “example@example.co”;
let cc = “”;
let subject = “Hey it’s a test”
let body = “Hey it’s a test to see if I can send email to multiple recipents”
sendEmailToPeople(sender,recipient,cc,subject,body)
.then(response=>{
console.log(response)
})
. catch (error=>{
console.log(error)
})
})
The response I got was undefined and no emails was sent. I have been tweaking different parts of the codes but I don’t know why it’s not working. Would anyone please suggest what to do? Thanks!