What I learned building my first AI email automation.
When I first started exploring AI automation, I decided the best way to learn was to build something real. Here's what broke, what I learned, and how those early mistakes shaped how I build these systems today.
The project was simple enough on paper: connect a WordPress lead generation database to an AI that could draft personalised email responses. I used n8n for the workflow automation and ChatGPT's API for generating the responses.
It took longer than expected. Not because the concept was hard, but because of real-world problems nobody warns you about—problems I now know to anticipate and avoid.
Problem 1: Microsoft authentication.
Connecting to Microsoft's email services via their Graph API should be straightforward. The documentation makes it look simple. It isn't.
OAuth tokens expire. When they do, your automation silently fails. No error message, no alert—just emails that never send. I spent a full day thinking my n8n workflow was broken before realising the token had expired overnight.
The fix involves setting up proper token refresh logic in n8n. You need to store the refresh token, check token validity before each send, and handle the refresh flow automatically. Microsoft's auth is notoriously fiddly—many developers avoid it entirely and use services like SendGrid or Resend instead.
Lesson: If you're building email automation for a client, seriously consider whether you need Microsoft integration at all. Third-party email services are more reliable and far easier to authenticate.
Problem 2: Context management.
The first version of my automation treated every email as a fresh conversation. The AI had no memory of previous exchanges. This meant responses were generic and sometimes contradicted what had been said before.
ChatGPT doesn't remember anything between API calls. If you want conversation continuity, you need to build it yourself. That means storing previous messages somewhere (I used a simple database table) and passing relevant context back to the API with each new request.
But here's the catch: you can't just dump the entire conversation history into the prompt. Token limits exist, and cost scales with input length. You need to be selective about what context you include.
I settled on including the last three exchanges plus any key information from the original lead form. This gave the AI enough context to respond coherently without ballooning API costs.
Lesson: Context management is where most AI automation projects get complicated. Plan for it from the start, not as an afterthought.
What actually worked.
Once I'd solved the auth and context problems, the system worked well. n8n handled the workflow logic—watching for new leads, triggering the AI, sending responses. ChatGPT generated genuinely useful draft emails that needed minimal editing.
The WordPress integration was surprisingly smooth. A simple webhook from the lead form to n8n was all it took. No plugins, no complexity.
The whole project reinforced something I now tell clients: AI automation isn't magic. It's plumbing. The AI part is often the easy bit. The hard part is authentication, data flow, error handling, and all the infrastructure around it.
What I now do differently.
- Skip Microsoft auth unless the client absolutely requires it. I use dedicated email services instead.
- Design context storage first. I decide how to handle conversation history before writing a single workflow.
- Build in logging from day one. When something fails silently, logs are the only way to diagnose it.
- Start with a simple use case. Lead response emails are a good starting point—low stakes, clear success criteria.
Worth the effort?
Absolutely. That early project taught me where AI automation actually gets difficult—and it's rarely the AI part. Now when I build these systems for clients, I know exactly where the pitfalls are. Authentication gets designed properly from day one. Context management is planned before we write a single workflow. Error handling and logging are built in, not bolted on.
The best way to master this stuff is to build it, break it, and fix it. Those early failures are exactly why our client projects run smoothly today.
Interested in AI automation for your business? We can help you avoid the pitfalls and build something that actually works.
Explore AI Services