Podcast Title

Author Name

0:00
0:00
Album Art

Build Your First AI Email Agent in Under 10 Minutes

By 10xdev team August 11, 2025

Have you been interested in learning about AI agents but feel overwhelmed and don't know where to start? There's a lot of information out there, and some of it can seem overly complicated. If you're just diving into this world, this article will guide you through creating a simple AI agent to help you grasp the fundamental concepts of how they work and how various tools come together.

This walkthrough will show you how to set up a basic and straightforward email agent. The goal is for you to understand why each piece is structured the way it is, how they connect, and how they function. By the end of this guide, you'll not only see what's possible but also have a foundational understanding to start building your own ideas.

How the AI Email Agent Works

First, let's look at what this AI email agent does. It's designed to check your contact list and send an email after you've given your approval.

Let's give it a simple command:

"Hey, can you ask Luke if he's performing this weekend?"

The AI agent will now search our contacts and draft an email. It then presents the draft for approval before sending it.

Here's the draft it generates:

Hi Luke, I hope you're doing well. I wanted to check in and see if you're performing this weekend.

Looks good. Let's approve it:

"Yes, let's send it."

The AI agent will now confirm the contact information and send the drafted email. If we check our sent folder in Gmail, we'll see the email has been sent to Luke, matching the text we just proofread.

Building the Agent from Scratch with N8N

Let's dive in and build this completely from scratch so you can understand exactly what’s going on.

We'll be using N8N, an excellent software for building automations, workflows, and AI agents. For this tutorial, we are using the free trial, which is available for 14 days. This allows you to try everything out, and all the tools and capabilities we use are available on the free plan.

Step 1: Create a Workflow and Set Up the Trigger

Once you log into N8N, you'll land on your home screen. Click Create workflow to start with a blank canvas.

The first thing we need is a trigger. A trigger is the action that kicks off the workflow. N8N has a built-in Chat Message Trigger, which is perfect for our needs.

When you add the Chat Message Trigger, a chat window will appear at the bottom of the screen. This allows you to send messages directly to your workflow. If you send a message now, you'll see the trigger node turn green, indicating it has fired.

Step 2: Add the AI Agent

With the trigger set up, click the + icon connected to it. A list of tools will appear. Navigate to the AI section and select the first option, AI Agent.

On the left-hand side, you'll see a log of all the information being passed through the workflow, including the chat input message. The AI Agent node automatically recognizes the chat message as its input, so we don't need to configure that part for now.

You'll notice the AI Agent has three "legs" sticking out: Chat Model, Memory, and Tools.

Step 3: Connect the Chat Model (The Brain)

The Chat Model is the brain of our AI agent. This is where we connect a Large Language Model (LLM). We have access to numerous models, but for this example, we'll focus on OpenAI, the LLM behind ChatGPT.

  1. Select the OpenAI Chat Model: Click on the Chat Model leg and choose OpenAI Chat Model.
  2. Create New Credentials: If you're new to N8N, you'll have some free OpenAI credits. However, to set up your own account, you'll need to create a new credential. This requires an API key.
  3. Get Your API Key: Go to platform.openai.com to get your key.
    • Create an account.
    • Provide an organization name (e.g., "Personal").
    • Skip inviting team members.
    • Choose to make your first API call and give your project a name (e.g., "YouTube email test").
    • Click Generate API key.
  4. Save the Key in N8N: Copy the generated API key, go back to N8N, and paste it into the credential field. Save it. Keep your API keys secret!

Note on Pricing: You need to pay for API credits, known as "tokens," on the OpenAI platform. This is separate from a paid ChatGPT subscription. The good news is that API tokens are incredibly cheap, costing a fraction of a penny per token. For most users, adding just $5 in credits can last for a month or more, depending on usage.

With your credential saved, you can now select a GPT model. I recommend sticking with GPT-4o or GPT-4.1. Different models yield different responses, so part of building an agent is testing which one works best for your goals.

Step 4: Configure Memory

Next, let's talk about Memory. This gives our agent a more enhanced brain, allowing it to remember the conversation. While there are advanced options like connecting to real databases, we'll start with the Simple Memory built into N8N.

Set the Context Window Length to a value between 15 and 50. This determines how many past interactions the model remembers. With memory, the agent can recall previous parts of the conversation.

For example, without memory:

You: "Hi, my name is Justin." Agent: "Great." You: "What's my name?" Agent: "I'm sorry, I don't know your name."

With memory enabled:

You: "Hey, my name is Justin." Agent: "Nice to meet you. How can I help?" You: "Do you remember my name?" Agent: "Yes, your name is Justin. How can I assist you?"

Step 5: Give the Agent Instructions (System Message)

Now, we need to give our agent a task. Open the AI Agent tool, go to Options, and add a System Message. This is where we provide the instructions and context for the agent's role.

Here are the instructions for our email assistant: You are an AI assistant designed to help me compose and send emails efficiently based on my text input. Follow this process: 1. Get the message and understand what I'm asking for. 2. Look up the recipient in the 'contact information' tool. 3. Write a draft of the email. 4. If I approve the draft, use the 'send email' tool to send it.

Step 6: Connect the Tools

The final step is to connect the tools the agent will use.

Tool 1: Google Sheets for Contacts 1. Add a Google Sheets tool. You'll need to connect your Google account by signing in and granting permissions. 2. Name the tool contact information. This is critical. The agent uses the tool's name to know which one to use, and it must match the name in your system message. 3. In the tool description, specify its purpose: "This tool is to reference my contacts and to access and retrieve their email addresses." 4. Select the Google Sheet file containing your contact list (a simple sheet with 'Name' and 'Email' columns will do).

Tool 2: Gmail for Sending Emails 1. Add a Gmail tool and connect your account. 2. Name the tool send email. 3. Set the description: "Once an email draft has been approved, use this tool to send the email to the recipient." 4. Set the Resource to Message and the Operation to Send. 5. For the Recipient and Subject Line fields, click the star icon to let the model define these values dynamically. 6. Set the Email Type to Text. 7. For the Message (the email body), also let the model define it. 8. Add your Sender Name. 9. Under Options, turn off Append N8N Attribution to remove the "sent by N8N" footer from your emails.

Testing Your AI Agent

Now that all the pieces are connected, you can run a test.

"Hey there, can you please send Morgan an email asking if he's free for lunch tomorrow?"

The agent should come back with a draft:

Hey Morgan, hope you're doing well. Are you free for lunch tomorrow? Let me know if you're available and what time works for you. Thanks, Justin.

If it looks good, approve it:

"Perfect. That looks great. Let's send it."

The agent will confirm the contact info and send the email. You've now successfully built your first AI agent!

Bonus: Using Free Large Language Models with OpenRouter

If you want to experiment without paying for OpenAI credits, you can use OpenRouter. It's a service that gives you access to numerous LLMs with a single API key.

  1. Replace the OpenAI Chat Model with the Open Router Chat Model.
  2. Create a new credential by getting an API key from openrouter.ai.
  3. Once connected, you can select from a vast list of models. Look for the ones with a price of zero, such as Google's Gemini 2.5 Pro Experimental or Meta's Llama models.

A Word of Caution: Free models can sometimes be less reliable for complex tasks like tool execution. During testing, a free model might understand the request and draft an email but fail to trigger the "send email" tool.

For reliable performance, especially in production, it's often recommended to use a premium, paid model. Putting even $5 into your OpenAI account can go a long way and ensure your agent functions as expected.

This has been a walkthrough of creating a basic AI agent and understanding it at a fundamental level. You should now have a solid foundation to set this up yourself and explore what AI agents can do. There is so much more to dive into, but for now, good luck with your AI agents!

Join the 10xdev Community

Subscribe and get 8+ free PDFs that contain detailed roadmaps with recommended learning periods for each programming language or field, along with links to free resources such as books, YouTube tutorials, and courses with certificates.

Recommended For You

Up Next