MailgentMailgent
Examples

Sales Outreach Agent

An agent that sends personalized outreach emails and handles replies

A sales agent that sends cold outreach, tracks responses, and follows up.

How It Works

1. Agent sends personalized outreach to prospects
2. When prospect replies, agent gets the full thread
3. Agent responds with relevant information
4. Labels track stage: outreach → replied → qualified → closed

Sending Outreach

prospects = [
    {"email": "alice@startup.com", "name": "Alice", "company": "Startup Inc"},
    {"email": "bob@bigcorp.com", "name": "Bob", "company": "BigCorp"},
]

for prospect in prospects:
    text = f"""Hi {prospect['name']},

I noticed {prospect['company']} is scaling fast. We help companies like yours
automate email workflows with AI agents.

Would you be open to a quick 15-min call this week?

Best,
Sales Agent"""

    res = requests.post(f"{BASE}/messages/send", headers=headers, json={
        "to": [prospect["email"]],
        "subject": f"AI email automation for {prospect['company']}",
        "text": text
    })

    # Label as outreach
    msg = res.json()
    requests.patch(
        f"{BASE}/messages/{msg['messageId']}",
        headers=headers,
        json={"addLabels": ["outreach", "pending-reply"]}
    )

Handling Replies

# Check for replies to outreach
res = requests.get(f"{BASE}/messages?labels=unread", headers=headers)

for msg in res.json()["messages"]:
    thread = requests.get(
        f"{BASE}/threads/{msg['threadId']}", headers=headers
    ).json()

    # Check if this is a reply to our outreach
    has_outreach = any("outreach" in m.get("labels", []) for m in thread["messages"])
    if not has_outreach:
        continue

    # Generate follow-up
    reply = generate_sales_reply(thread["messages"])

    requests.post(
        f"{BASE}/messages/{msg['messageId']}/reply",
        headers=headers,
        json={"text": reply}
    )

    requests.patch(
        f"{BASE}/messages/{msg['messageId']}",
        headers=headers,
        json={
            "addLabels": ["read", "replied"],
            "removeLabels": ["unread", "pending-reply"]
        }
    )

Track Pipeline

# Prospects who haven't replied
GET /v0/messages?labels=pending-reply

# Prospects who replied
GET /v0/messages?labels=replied

# Qualified leads
GET /v0/messages?labels=qualified

On this page