i have been using pro plan of ghost. so I would like to send newsletters by email using admin apikey. let me know example code
my source node code follow that :
async function createAndSendPost() {
try {
// Create a new post
const post = await api.posts.add({
title: 'Your Email Title',
html: '<p>This is the content of your email</p>',
status: 'draft', // Initially save as draft
email_only: true // Ensure it's an email-only post
});
// Update post to publish and send as email
await api.posts.edit({
id: post.id,
status: 'published',
updated_at: post.updated_at // Include the updated_at field
}, { send_email: true });
console.log('Email sent successfully!');
} catch (err) {
console.error('Error sending email:', err);
}
}
createAndSendPost();