Skip to content

Instantly share code, notes, and snippets.

@kenny-io
Created April 6, 2024 11:16
Show Gist options
  • Save kenny-io/8da5e2c169efc303a664a0c9a66bd3f5 to your computer and use it in GitHub Desktop.
Save kenny-io/8da5e2c169efc303a664a0c9a66bd3f5 to your computer and use it in GitHub Desktop.
export default async (req) => {
const { next_run } = await req.json()
// Fetch the latest blog posts
const response = await fetch(`https://mysite.com/api/blog-posts`);
const blogPosts = await response.json();
// Compile email content
for (const blogPost of blogPosts) {
emailContent += `
<h2>${blogPost.title}</h2>
<p>${blogPost.summary}</p>
<a href="${blogPost.URL}">Read more</a><br>`;
}
const subscribers = await getSubscribers();
// Send email to all subscribers
await sendEmail(emailContent, subscribers);
console.log("Next email will be sent at:", next_run)
}
// function to fetch subscribers
async function getSubscribers() {
// Fetch subscribers from somewhere
return ['[email protected]', '[email protected]'];
}
// function for sending the email
async function sendEmail(emailContent, subscribers) {
// In a real application, you'd integrate with an email sending service here.
subscribers.forEach(subscriber => {
// Send email logic here
console.log(`Email sent to: ${subscriber}`);
});
}
export const config = {
schedule: "@hourly"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment