Quickstart

Create your first inbox with the AgentMail API

Quickest start

$pip install agentmail

Get your API key from the Console and replace am_... in the code below.

1from agentmail import AgentMail
2
3client = AgentMail(api_key="am_...")
4inbox = client.inboxes.create()
5client.inboxes.messages.send(inbox.inbox_id, to="user@example.com", subject="Hello", text="Hello from my agent!")

Copy for Cursor / Claude

Copy one of the blocks below into Cursor or Claude for a complete, working AgentMail integration. Each block includes setup, API reference, error handling, rate limiting, and idempotency guidance.

1"""
2AgentMail Python Quickstart — copy into Cursor/Claude for instant setup.
3
4Setup: pip install agentmail python-dotenv. Set AGENTMAIL_API_KEY in .env.
5
6API reference:
7- inboxes.create(username?, domain?, display_name?, client_id?) — client_id for idempotent retries
8- messages.send(inbox_id, to, subject, text, html?, cc?, bcc?, reply_to?, attachments?)
9- messages.list(inbox_id, limit?, page_token?, labels?) — receive emails; use extracted_text/extracted_html for reply content
10
11Errors: SDK raises on 4xx/5xx. Inspect error.body.message or str(e).
12Rate limit: 429 with Retry-After header. Implement exponential backoff for retries.
13Idempotency: Pass client_id to inboxes.create() to safely retry without duplicates.
14"""
15import os
16from dotenv import load_dotenv
17from agentmail import AgentMail
18
19load_dotenv()
20client = AgentMail(api_key=os.getenv("AGENTMAIL_API_KEY"))
21
22# Create inbox (client_id enables safe retries)
23inbox = client.inboxes.create(client_id="my-agent-inbox-v1")
24
25# Send email
26try:
27 client.inboxes.messages.send(
28 inbox.inbox_id,
29 to="recipient@example.com",
30 subject="Hello from AgentMail",
31 text="Plain text body",
32 html="<p>HTML body</p>",
33 )
34except Exception as e:
35 # Handle validation, not found, rate limit (429), etc.
36 print(f"Send failed: {e}")
37 raise
38
39# Receive messages
40for msg in client.inboxes.messages.list(inbox.inbox_id, limit=10).messages:
41 print(msg.subject, msg.extracted_text or msg.text)

When receiving emails, messages include extracted_text and extracted_html for reply content without quoted history.

This guide will walk you through installing the AgentMail SDK, authenticating with your API key, and creating your first email inbox.

1

Access the AgentMail Console

First, you’ll need to access the AgentMail Console to manage your account and API keys. Click the link below to get started.

If you don’t have an account yet, you can sign up directly from the console. Once you’re logged in, you’ll be able to manage your inboxes, view analytics, and create API keys.

2

Create an API Key

Now that you’re in the console, you’ll need to create an API key to authenticate your requests. Navigate to the API Keys section in your console dashboard. API Key Creation Screenshot Click “Create New API Key” and give it a descriptive name. Once created, copy the API key and store it securely. Create a .env file in your project’s root directory and add your key to it. We recommend using environment variables to keep your keys secure.

3

Install the SDK

Install the AgentMail SDK using your preferred package manager. We’ll also use a library to load the environment variable from the .env file.

$pip install agentmail python-dotenv
4

Create an inbox and send an email

Now you’re ready to make your first API call. Create a new file (e.g., quickstart.py or quickstart.ts) and add the following code. This script will initialize the AgentMail client, create a new inbox, and then send a test email.

1import os
2from dotenv import load_dotenv
3from agentmail import AgentMail
4
5# Load the API key from the .env file
6load_dotenv()
7api_key = os.getenv("AGENTMAIL_API_KEY")
8
9# Initialize the client
10client = AgentMail(api_key=api_key)
11
12# Create an inbox
13print("Creating inbox...")
14inbox = client.inboxes.create() # domain is optional
15print("Inbox created successfully!")
16print(inbox)
17
18# Send Email
19
20client.inboxes.messages.send(
21 inbox.inbox_id,
22 to="your-email@example.com",
23 subject="Hello from AgentMail!",
24 text="This is my first email sent with the AgentMail API.",
25)

The domain parameter is optional. If not provided, AgentMail will use the default @agentmail.to domain. If you would like a custom domain, please upgrade to a paid plan.

5

Run the code

Execute the script from your terminal.

$python quickstart.py

You should see the details of your newly created inbox printed to the console. Congratulations, you’ve successfully created your first AgentMail inbox!

Next Steps

Congrats, you sent your first email via AgentMail. But this isn’t our strength. Explore the full power of creating agents that can autonomously reply, take action, parse attachments, semantically search your inbox, by exploring our docs and tutorials below.

Looking for a different language? Email us at support@agentmail.cc and we’ll get you set up.