// Initialize client
const client = new EmailClient({
apiKey: process.env.CTCT_API_KEY,
apiSecret: process.env.CTCT_SECRET
});
// Authenticate
await client.authenticate();
// Get contact lists
const lists = await client.getContactLists();
const enterpriseList = lists.find(
(list) => list.name === "Enterprise Leads"
);
// Create template
const template = await client.createTemplate({
name: "Welcome Email",
subject: "Welcome to our platform",
body: generateEmailHTML()
});
// Send emails
for (const contact of enterpriseList.contacts) {
try {
await client.sendEmail({
to: contact.email,
templateId: template.id,
variables: {
firstName: contact.firstName,
company: contact.company
}
});
await sleep(100); // Rate limiting
} catch (error) {
console.error(`Failed for ${contact.email}`);
}
}~45 lines of boilerplate, manual error handling, rate limiting concerns
