Replit

Integrate AgentMail with your Replit apps and agents

Getting started

Replit is a cloud-based app and agent builder with a built in IDE, AI assistant, and deployment infrastructure.

AgentMail is a “connector” integration on Replit, meaning your Replit apps and agents can use it directly.

Setup

Navigate to the Intregrations tab in the Replit builder. Find AgentMail and click Connect/Sign in. Then paste in your AgentMail API key from the AgentMail Console. That’s it.

How it works

Replit uses Mastra, a TypeScript framework for building agents. Everytime you create a new app/agent Replit will generate a set of Mastra tools to interface with the AgentMail API, based on your use case and requirements.

Below is a collections of prebuilt tools that Replit can use out of the box to serve virtually any use case.

Tools

TypeScript
1import { createTool } from '@mastra/core/tools'
2import { z } from 'zod'
3
4import { AgentMailClient } from 'agentmail'
5
6const ListItemsInput = z.object({
7 limit: z.number().optional().describe('Max number of items to return'),
8 pageToken: z.string().optional().describe('Pagination page token'),
9})
10
11const InboxId = z.string().describe('ID of inbox')
12
13const GetInboxInput = z.object({ inboxId: InboxId })
14
15const CreateInboxInput = z.object({
16 username: z.string().optional().describe('Username'),
17 domain: z.string().optional().describe('Domain'),
18 displayName: z.string().optional().describe('Display name'),
19})
20
21const ListInboxItemsInput = ListItemsInput.extend({
22 inboxId: InboxId,
23 labels: z.array(z.string()).optional().describe('Filter items with labels'),
24 before: z.coerce.date().optional().describe('Filter items before datetime'),
25 after: z.coerce.date().optional().describe('Filter items after datetime'),
26})
27
28const GetThreadInput = GetInboxInput.extend({
29 threadId: z.string().describe('ID of thread'),
30})
31
32const MessageId = z.string().describe('ID of message')
33
34const BaseMessageInput = z.object({
35 inboxId: InboxId,
36 text: z.string().optional().describe('Plain text body'),
37 html: z.string().optional().describe('HTML body'),
38 labels: z.array(z.string()).optional().describe('Labels'),
39})
40
41const SendMessageInput = BaseMessageInput.extend({
42 to: z.union([z.string(), z.array(z.string())]).describe('To recipients'),
43 cc: z
44 .union([z.string(), z.array(z.string())])
45 .optional()
46 .describe('CC recipients'),
47 bcc: z
48 .union([z.string(), z.array(z.string())])
49 .optional()
50 .describe('BCC recipients'),
51 subject: z.string().optional().describe('Subject'),
52})
53
54const ReplyToMessageInput = BaseMessageInput.extend({ messageId: MessageId })
55
56const UpdateMessageInput = z.object({
57 inboxId: InboxId,
58 messageId: MessageId,
59 addLabels: z.array(z.string()).optional().describe('Labels to add'),
60 removeLabels: z.array(z.string()).optional().describe('Labels to remove'),
61})
62
63const listInboxesTool = createTool({
64 id: 'list-inboxes',
65 description: 'List inboxes',
66 inputSchema: ListItemsInput,
67 execute: ({ context }) => {
68 const client = new AgentMailClient()
69 return client.inboxes.list(context)
70 },
71})
72
73const createInboxTool = createTool({
74 id: 'create-inbox',
75 description: 'Create inbox',
76 inputSchema: CreateInboxInput,
77 execute: ({ context }) => {
78 const client = new AgentMailClient()
79 return client.inboxes.create(context)
80 },
81})
82
83const deleteInboxTool = createTool({
84 id: 'delete-inbox',
85 description: 'Delete inbox',
86 inputSchema: GetInboxInput,
87 execute: ({ context }) => {
88 const client = new AgentMailClient()
89 return client.inboxes.delete(context.inboxId)
90 },
91})
92
93const listThreadsTool = createTool({
94 id: 'list-threads',
95 description: 'List threads',
96 inputSchema: ListInboxItemsInput,
97 execute: ({ context }) => {
98 const client = new AgentMailClient()
99 return client.inboxes.threads.list(context.inboxId, context)
100 },
101})
102
103const getThreadTool = createTool({
104 id: 'get-thread',
105 description: 'Get thread and its messages',
106 inputSchema: GetThreadInput,
107 execute: ({ context }) => {
108 const client = new AgentMailClient()
109 return client.inboxes.threads.get(context.inboxId, context.threadId)
110 },
111})
112
113const sendMessageTool = createTool({
114 id: 'send-message',
115 description: 'Send message',
116 inputSchema: SendMessageInput,
117 execute: ({ context }) => {
118 const client = new AgentMailClient()
119 return client.inboxes.messages.send(context.inboxId, context)
120 },
121})
122
123const replyToMessageTool = createTool({
124 id: 'reply-to-message',
125 description: 'Reply to message',
126 inputSchema: ReplyToMessageInput,
127 execute: ({ context }) => {
128 const client = new AgentMailClient()
129 return client.inboxes.messages.reply(context.inboxId, context.messageId, context)
130 },
131})
132
133const updateMessageTool = createTool({
134 id: 'update-message',
135 description: 'Update message',
136 inputSchema: UpdateMessageInput,
137 execute: ({ context }) => {
138 const client = new AgentMailClient()
139 return client.inboxes.messages.update(context.inboxId, context.messageId, context)
140 },
141})
142
143export const tools = {
144 listInboxesTool,
145 createInboxTool,
146 deleteInboxTool,
147 listThreadsTool,
148 getThreadTool,
149 sendMessageTool,
150 replyToMessageTool,
151 updateMessageTool,
152}

About AgentMail

AgentMail is the email inbox API for AI agents. It gives agents their own email inboxes, like Gmail does for humans. Unlike other email APIs, AgentMail is for both sending and receiving, supporting two-way email conversations.

Email is critical to identity and communication on the internet. Much of the context that people use for their work exists within email. AgentMail enables AI agents to meet people where they work and use the internet like humans do.

Features

  1. Programmatic inboxes: Create, manage, and delete inboxes via API
  2. Threads and replies: Facilitate 2-way emals conversations with persistant and relevant context
  3. Attachments: Send, receive, and download attachments so agents can work with documents
  4. Realtime events: Build event-driven agents and systems with Webhooks and Websockets
  5. Custom domains: Whitelabel your or your customers’ inboxes to automate client-facing work
  6. Language/Framework SDKs: Use your prefered language and framework

Use cases

  1. Process inbound: Receive, triage, and process inbound emails
  2. Automate outbound: Draft, schedule, and send outbound emails
  3. Join conversations: Address an agent directly or CC it in an existing email thread
  4. Identify and authenticate: Agents can sign up, receive 2FA code, and authenticate with any application

Verticals

  1. Operations: Automate internal workflows, vendor communications, and cross-team coordination
  2. Support: Handle customer inquiries, ticket management, and automated responses at scale
  3. Procurement: Streamline vendor onboarding, RFP processes, and purchase order management
  4. Sales: Automate lead qualification, follow-ups, and customer outreach campaigns
  5. Recruiting: Automate candidate outreach, interview scheduling, and applicant communication

These are just a few select verticals, but we have seen AgentMail be effective in automating any email task across every function. If a human does it with email, it can be automated with AgentMail.