"Send a daily summary email" sounds trivial, and the first version an AI gives you will run. It'll also, quietly, do several wrong things: fire at an unpredictable time, stop if your app restarts, and — if one address bounces — abandon everyone after it. Do this carelessly and you don't just annoy users; you get your sending domain flagged as spam, which is hard to undo.
Here's the request three ways to Claude via Claude Code, with the real code. This one is less about security and more about the difference between "technically sends an email" and "sends the right email, once, on time."
The same request, three ways
"Send a daily summary email", three ways
Each prompt was given to Claude, via Claude Code (26 Sep 2026) on its own. Outputs verbatim.
send a daily summary email
setInterval(async () => {
const users = await getUsers();
for (const u of users) await sendEmail(u.email, summary(u));
}, 24 * 60 * 60 * 1000);worseIt relies on your app running forever, fires 24 hours after each deploy (not at a set time), and one failure in the loop kills every send after it.
send a daily summary email on a schedule (08:00) using a real email provider, not setInterval
// scheduled function — cron: "0 8 * * *" (08:00 daily)
export async function scheduled() {
const users = await getUsers();
for (const u of users) {
await resend.emails.send({
from: 'Aliteq <hello@example.com>',
to: u.email,
subject: 'Your daily summary',
html: summary(u),
});
}
}it dependsA cron schedule fires at a real time (08:00 daily); a proper email API handles delivery, with its key in an env var.
same, but run in the background, only email users who opted in, never send twice for the same day, and don't let one failed send stop the rest
export async function scheduled() {
const today = new Date().toISOString().slice(0, 10);
const users = await getUsers({ subscribed: true }); // respect opt-out
for (const u of users) {
if (await alreadySent(u.id, today)) continue; // no double-send
try {
await resend.emails.send({
from: 'Aliteq <hello@example.com>',
to: u.email,
subject: 'Your daily summary',
html: summary(u),
});
await markSent(u.id, today);
} catch (err) {
await logFailure(u.id, err); // one failure ≠ all fail
}
}
}betterThe three lines that matter: the subscribed filter (opt-out), the alreadySent guard (no duplicates), and the try/catch (one bad address doesn't sink the whole batch).
What changed: "Send an email" is one line; "send the right email once, on time, to the right people, without one failure breaking the rest" is the spec that keeps you off spam lists.
The setInterval version is the tell of a prompt that didn't mention scheduling. It works on your laptop and looks fine in a demo, but on a real host it restarts with every deploy and fires whenever it feels like it. Asking for a cron schedule moves it onto real infrastructure that fires at a real time.




