# Send AgentMail sending and receiving with Python scripts to your agent
Hand the extracted package to your coding agent with a concrete install brief instead of figuring it out manually.
## Fast path
- Download the package from Yavira.
- Extract it into a folder your agent can access.
- Paste one of the prompts below and point your agent at the extracted folder.
## Suggested prompts
### New install

```text
I downloaded a skill package from Yavira. Read SKILL.md from the extracted folder and install it by following the included instructions. Tell me what you changed and call out any manual steps you could not complete.
```
### Upgrade existing

```text
I downloaded an updated skill package from Yavira. Read SKILL.md from the extracted folder, compare it with my current installation, and upgrade it while preserving any custom configuration unless the package docs explicitly say otherwise. Summarize what changed and any follow-up checks I should run.
```
## Machine-readable fields
```json
{
  "schemaVersion": "1.0",
  "item": {
    "slug": "python-agentmail-send-receive",
    "name": "AgentMail sending and receiving with Python scripts",
    "source": "tencent",
    "type": "skill",
    "category": "开发工具",
    "sourceUrl": "https://clawhub.ai/lausser/python-agentmail-send-receive",
    "canonicalUrl": "https://clawhub.ai/lausser/python-agentmail-send-receive",
    "targetPlatform": "OpenClaw"
  },
  "install": {
    "downloadUrl": "/downloads/python-agentmail-send-receive",
    "sourceDownloadUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=python-agentmail-send-receive",
    "sourcePlatform": "tencent",
    "targetPlatform": "OpenClaw",
    "packageFormat": "ZIP package",
    "primaryDoc": "SKILL.md",
    "includedAssets": [
      "send_email.py",
      "check_mail.py",
      "SKILL.md"
    ],
    "downloadMode": "redirect",
    "sourceHealth": {
      "source": "tencent",
      "status": "healthy",
      "reason": "direct_download_ok",
      "recommendedAction": "download",
      "checkedAt": "2026-04-23T16:43:11.935Z",
      "expiresAt": "2026-04-30T16:43:11.935Z",
      "httpStatus": 200,
      "finalUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=4claw-imageboard",
      "contentType": "application/zip",
      "probeMethod": "head",
      "details": {
        "probeUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=4claw-imageboard",
        "contentDisposition": "attachment; filename=\"4claw-imageboard-1.0.1.zip\"",
        "redirectLocation": null,
        "bodySnippet": null
      },
      "scope": "source",
      "summary": "Source download looks usable.",
      "detail": "Yavira can redirect you to the upstream package for this source.",
      "primaryActionLabel": "Download for OpenClaw",
      "primaryActionHref": "/downloads/python-agentmail-send-receive"
    },
    "validation": {
      "installChecklist": [
        "Use the Yavira download entry.",
        "Review SKILL.md after the package is downloaded.",
        "Confirm the extracted package contains the expected setup assets."
      ],
      "postInstallChecks": [
        "Confirm the extracted package includes the expected docs or setup files.",
        "Validate the skill or prompts are available in your target agent workspace.",
        "Capture any manual follow-up steps the agent could not complete."
      ]
    }
  },
  "links": {
    "detailUrl": "https://openagent3.xyz/skills/python-agentmail-send-receive",
    "downloadUrl": "https://openagent3.xyz/downloads/python-agentmail-send-receive",
    "agentUrl": "https://openagent3.xyz/skills/python-agentmail-send-receive/agent",
    "manifestUrl": "https://openagent3.xyz/skills/python-agentmail-send-receive/agent.json",
    "briefUrl": "https://openagent3.xyz/skills/python-agentmail-send-receive/agent.md"
  }
}
```
## Documentation

### Skill: Email via agentmail

You can send and receive email as REPLACE_WITH_IDENTITY@agentmail.to using two Python scripts.
The scripts live in this skill folder and are deployed to ~/.openclaw/workspace/agentmail/.
The scripts contain placeholders which need to be replaced with real-life value:

REPLACE_WITH_IDENTITY
REPLACE_WITH_THE_HUMANS_EMAIL_ADDRESS

### Deploy the skill

Copy the scripts and create the venv in the workspace:

DEST=~/.openclaw/workspace/agentmail
SKILL_DIR="$(dirname "$(readlink -f "$0")")"    # if running from a script
# or just point SKILL_DIR to this skill folder

mkdir -p "$DEST"
cp "$SKILL_DIR/check_mail.py" "$SKILL_DIR/send_email.py" "$DEST/"

cd "$DEST"

# Create venv (prefer uv, fall back to python)
if command -v uv &>/dev/null; then
  uv venv venv
  uv pip install --python venv/bin/python agentmail python-dotenv
else
  python3 -m venv venv
  venv/bin/pip install agentmail python-dotenv
fi

### Create the .env file

cat > ~/.openclaw/workspace/agentmail/.env << 'EOF'
AGENTMAIL_API_KEY=am_us_.....
EOF

This is only necessary if you don't have the environment variable in your running environment or if you can't read it from your openclaw.json config file.

### Verify

cd ~/.openclaw/workspace/agentmail
source venv/bin/activate
python check_mail.py        # should print "No new mail." on a fresh inbox

### Run

cd ~/.openclaw/workspace/agentmail
source venv/bin/activate
python check_mail.py

This downloads all unread messages as JSON files into the workspace directory and marks them as read. Running it again only fetches new mail.

### Output files

Each message is saved as MAIL.<YYYYMMDDTHHmmss>.<NNN> — timestamp from the message, 3-digit sequence number within the batch.

Example: MAIL.20260226T134244.001

The JSON inside contains:

{
  "message_id": "<...>",
  "thread_id": "...",
  "timestamp": "2026-02-26 13:42:44+00:00",
  "from": "Sender Name <sender@example.com>",
  "to": ["REPLACE_WITH_IDENTITY@agentmail.to"],
  "cc": null,
  "subject": "Re: Hello",
  "text": "Plain-text body...",
  "html": "<p>HTML body...</p>",
  "labels": ["received", "unread"],
  "in_reply_to": "<original-message-id>",
  "attachments": []
}

### Reading downloaded mail

# List all mail files (oldest first)
ls -1 MAIL.* 2>/dev/null | sort

# Read one
cat MAIL.20260226T134244.001

# Extract just the text body
python -c "import json,sys; print(json.load(open(sys.argv[1]))['text'])" MAIL.20260226T134244.001

### Exit codes

CodeMeaning0Success (mail downloaded or inbox empty)1Missing API key2API error on initial listing3Total failure (all messages errored)

### Run

cd ~/.openclaw/workspace/agentmail
source venv/bin/activate
python send_email.py

send_email.py is a template with hardcoded recipient/subject/body. For real use, modify its parameters or write a one-off script using the same pattern:

import os
from dotenv import load_dotenv
from agentmail import AgentMail

load_dotenv()
client = AgentMail(api_key=os.getenv("AGENTMAIL_API_KEY"))

client.inboxes.messages.send(
    inbox_id="REPLACE_WITH_IDENTITY@agentmail.to",
    to="recipient@example.com",
    subject="Subject line",
    text="Plain-text body.",
)

### send() parameters

ParameterRequiredDescriptioninbox_idyesAlways "REPLACE_WITH_IDENTITY@agentmail.to"toyesRecipient email addresssubjectnoSubject linetextnoPlain-text bodyhtmlnoHTML bodyccnoCC addressesbccnoBCC addresses

### 4. Replying to a Message

To reply in the same thread, use reply() with the message_id from a downloaded MAIL.* file:

import json, os
from dotenv import load_dotenv
from agentmail import AgentMail

load_dotenv()
client = AgentMail(api_key=os.getenv("AGENTMAIL_API_KEY"))

# Load the message you want to reply to
with open("MAIL.20260226T134244.001") as f:
    msg = json.load(f)

client.inboxes.messages.reply(
    inbox_id="REPLACE_WITH_IDENTITY@agentmail.to",
    message_id=msg["message_id"],
    text="This is my reply.",
)

This preserves threading — the reply appears in the same conversation as the original.

### 5. Typical Workflow

Check mail: python check_mail.py
Read: inspect the MAIL.* files that were created
Process: act on the content of each message
Reply if needed: use the reply() pattern from section 4
Clean up: rm MAIL.* when done processing
Repeat: run check_mail.py again later for new messages
## Trust
- Source: tencent
- Verification: Indexed source record
- Publisher: lausser
- Version: 1.0.0
## Source health
- Status: healthy
- Source download looks usable.
- Yavira can redirect you to the upstream package for this source.
- Health scope: source
- Reason: direct_download_ok
- Checked at: 2026-04-23T16:43:11.935Z
- Expires at: 2026-04-30T16:43:11.935Z
- Recommended action: Download for OpenClaw
## Links
- [Detail page](https://openagent3.xyz/skills/python-agentmail-send-receive)
- [Send to Agent page](https://openagent3.xyz/skills/python-agentmail-send-receive/agent)
- [JSON manifest](https://openagent3.xyz/skills/python-agentmail-send-receive/agent.json)
- [Markdown brief](https://openagent3.xyz/skills/python-agentmail-send-receive/agent.md)
- [Download page](https://openagent3.xyz/downloads/python-agentmail-send-receive)