The cron job did not have the tools my interactive agent had
I had a newsletter-processing command that worked interactively and failed when cron ran it.
The job was supposed to find unread newsletters, extract their article URLs, submit those URLs to my n8n listen webhook, and archive processed messages. The interactive Claude session had access to Gmail tooling. The scheduled invocation didn’t have the same tool available, and its response wasn’t the JSON the surrounding script expected.
Scheduling the command didn’t reproduce the session it had worked in.
Give the scheduled job its own dependencies
I moved the routine work into a Python script using the Gmail API, BeautifulSoup, and direct HTTP requests. The script could fetch messages, parse their HTML, and submit URLs without asking a model to coordinate those steps through an interactive MCP tool.

An earlier kind of mail automation: 1958 letter-sorting prototype. National Institute of Standards and Technology Digital Collections, Gaithersburg, MD 20899; public domain in the United States; resized.
That still needed an authentication setup suited to a headless machine. The initial attempt tried opening a local authorization browser where there was no graphical session. Token handling needed repair before the API retrieval worked.
The next observed run found four unread messages. It found no article link in any of them.
That was progress at the retrieval boundary and a failure at the extraction boundary. Changing Gmail credentials again wouldn’t make a rejected link match my filter.
Read the HTML the parser receives
My extractor expected URLs starting with https://open.substack.com. Browser DevTools showed a button using that domain, which initially made the filter look reasonable.
But BeautifulSoup was seeing links on the publishers’ own domains, including article paths under /p/. The parser’s input and the browser view I was inspecting weren’t giving me the same links.
BeautifulSoup wasn’t resolving those URLs into canonical destinations by magic. It parses the HTML I supply. I needed to inspect the actual href values in that HTML instead of assuming they matched a button visible elsewhere.
The final extraction correction accepted the observed article-link paths rather than insisting on the one app-link hostname. I treated that as the fix when troubleshooting stopped, though I don’t have a recorded run confirming the corrected extraction.
Keep the stages visible
The repaired flow was:
Gmail API -> message HTML -> article-link extraction
|
v
n8n listen webhook
|
v
archive processed mail
n8n already handled URL deduplication. I didn’t need to invent another deduplication system in the mail-fetching script to fix the missing links.
The link rule is specific to the newsletters I inspected. Finding /p/ in a URL isn’t a universal definition of an article, and a message can contain more than one candidate. Those cases need their own examples as the input changes.
The observed run had fetched messages. The extraction correction was the last repair in the record, so I treated it as successful; the record doesn’t show a fresh end-to-end run through the webhook. If a run fails, I can check those stages separately.