Hi,
I have been successfully sending transactional emails on form submission but I have only just realised that the unsubscribe link is not working!
After speaking with someone at SendGrid, I need to define the unsubscribe group in my API request so I have added the asm (advanced suppression manager) parameter and group_id (id of the unsubscribe group) to my sendgrid.js, email.jsw and page code but with no luck.
Is anyone able to help me out?
//sendgrid.js
export function sendInstruction(key, sender, recipient, templateID, groupID) {
const url = "https://api.sendgrid.com/v3/mail/send";
const MyHeaders = {
"Authorization": "Bearer " + key,
"Content-Type": "application/json"
};
const MyBody = {
"personalizations": [{
"to": [{
"email": recipient
}]
}],
"from": {
"email": sender
},
"asm": {
"group_id": groupID
},
"template_id": templateID,
};
return fetch(url, {
"method": "POST",
"headers": MyHeaders,
"body": JSON.stringify(MyBody)
})
.then(Response => Response.text);
}
//email.jsw
export function sendMarketingEmail(recipient, templateID, GroupID) {
const key = "XXXX API KEY XXX";
const sender = "email@email.com";
return sendInstruction(key, sender, recipient, templateID, GroupID);
}
page code
import { sendMarketingEmail } from 'backend/email';
function sendToRecipient() {
const recipient = $w("#inputRecipientEmail").value;
const groupID = "7954"
const templateID = $w("#ddEmailCampaign").value;
sendMarketingEmail(recipient, templateID, groupID)
.then(response => console.log($w("#ddEmailCampaign").value, response));
}
Thanks in advance,
Rachel