HI Team,
SendGrid supports the capability to send the single email to one or more recipients in the TO field plus one or more recipients in the CC or BCC fields (reference here: Personalizations | Twilio). Does the WIX SendGrid function support this capability?
Using the code below I have been able to send the single email to the submitter of the form (in the TO field) plus one person in the CC field, but not two addresses CC’d as is my requirement.
Any guidance here very much appreciated!
=========================================
Form Event Handler
import { sendEmail, sendEmailWithRecipient } from ‘backend/email’;
$w.onReady( function () {
$w(“#NominationTestdataset”).onAfterSave(sendFormData);
});
function sendFormData() {
const subject = New Regionals Nomination
;
const body = Hi ${$w("#firstnameInput").value}, \r \rThis email confirms your nomination **for** the tournament. \r \rFirst Name: ${$w("#firstnameInput").value} \rSurname: ${$w("#surnameInput").value} \rEmail: ${$w("#emailInput").value} \r \rRegards, \rThe Committee
;
const recipient = $w(“#emailInput”).value;
const nomcc = “email1@outlook.com;email2@outlook.com”;
sendEmailWithRecipient(subject, body, recipient, nomcc)
.then(response => console.log(response));
}
=========================================
import { sendWithService } from ‘backend/sendGrid’;
export function sendEmail(subject, body) {
const key = “nnnnnnnnnnnMyAPIKeynnnnnnnnnnnnnnnnnnnnn”;
const sender = “from.email@domain.com”;
const recipient = “to.email@domain.com”;
return sendWithService(key, sender, recipient, subject, body);
}
export function sendEmailWithRecipient(subject, body, recipient, nomcc) {
const key = “nnnnnnnnnnnMyAPIKeynnnnnnnnnnnnnnnnnnnnn”;
const sender = “TheSender@outlook.com”;
return sendWithService(key, sender, recipient, nomcc, subject, body);
}
=========================================
import { fetch } from ‘wix-fetch’;
export function sendWithService(key, sender, recipient, nomcc, 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}&cc=${nomcc}&subject=${subject}&text=${body}
;
const request = {
“method”: “post”,
“headers”: headers,
“body”: data
};
return fetch(url, request)
.then(response => response.json());
}