Connect Google Gemini's function calling to MultiMail for sending, reading, and managing email — with human oversight layered on top of Gemini's safety settings.
Google's Gemini API provides function calling and grounding capabilities that make it well-suited for building agentic applications. MultiMail gives Gemini models a complete email infrastructure layer, enabling your agents to send, receive, read, and reply to emails through structured function calls.
By integrating MultiMail with the Gemini API, your agents gain email capabilities while benefiting from two layers of safety: Gemini's built-in safety settings handle content filtering, and MultiMail's oversight modes handle email-specific authorization. The default gated_send mode means Gemini drafts emails but a human approves before delivery.
Connect Gemini to MultiMail by defining email functions using Gemini's function declaration format and routing calls to the MultiMail REST API. Gemini also supports automatic function calling, which can streamline your agent loop.
Gemini's built-in safety settings filter harmful content at the model level. MultiMail adds email-specific oversight on top, so you get content safety from Google and send authorization from MultiMail's oversight modes.
Gemini's function calling accepts structured declarations that map directly to MultiMail's email operations. Define send_email, check_inbox, and reply_email as function declarations with typed parameters.
Gemini supports automatic function calling where the SDK handles the tool execution loop. Combined with MultiMail's API, this simplifies building email agents to just defining functions and connecting endpoints.
Gemini's multimodal capabilities let your agent process email attachments — images, PDFs, and documents — alongside text content. MultiMail handles the email transport while Gemini analyzes the content.
Start with gated_send (Gemini composes, human approves) and progress to monitored or autonomous as trust builds. MultiMail supports five oversight modes to match agent autonomy to your confidence level.
import google.generativeai as genai
import requests
genai.configure(api_key="your_gemini_api_key")
MULTIMAIL_API = "https://api.multimail.dev/v1"
MM_HEADERS = {"Authorization": "Bearer mm_live_your_api_key"}
send_email_fn = genai.protos.FunctionDeclaration(
name="send_email",
description="Send an email through MultiMail. In gated_send mode, queues for human approval.",
parameters=genai.protos.Schema(
type=genai.protos.Type.OBJECT,
properties={
"mailbox_id": genai.protos.Schema(type=genai.protos.Type.STRING),
"to": genai.protos.Schema(type=genai.protos.Type.STRING),
"subject": genai.protos.Schema(type=genai.protos.Type.STRING),
"body": genai.protos.Schema(type=genai.protos.Type.STRING)
},
required=["mailbox_id", "to", "subject", "body"]
)
)
check_inbox_fn = genai.protos.FunctionDeclaration(
name="check_inbox",
description="Check the inbox for recent messages.",
parameters=genai.protos.Schema(
type=genai.protos.Type.OBJECT,
properties={
"mailbox_id": genai.protos.Schema(type=genai.protos.Type.STRING),
"limit": genai.protos.Schema(type=genai.protos.Type.INTEGER)
},
required=["mailbox_id"]
)
)
email_tools = genai.protos.Tool(function_declarations=[send_email_fn, check_inbox_fn])Create function declarations for email tools using Gemini's native function calling format.
def execute_function(name, args):
if name == "send_email":
resp = requests.post(f"{MULTIMAIL_API}/send", headers=MM_HEADERS, json=dict(args))
elif name == "check_inbox":
resp = requests.get(
f"{MULTIMAIL_API}/mailboxes/{args[&"cm">#039;mailbox_id']}/inbox",
headers=MM_HEADERS, params={"limit": args.get("limit", 10)}
)
elif name == "reply_email":
resp = requests.post(f"{MULTIMAIL_API}/reply", headers=MM_HEADERS, json=dict(args))
else:
return {"error": f"Unknown function: {name}"}
return resp.json()
model = genai.GenerativeModel(
model_name="gemini-2.0-flash",
tools=[email_tools],
system_instruction="You are an email assistant. Emails are sent in gated_send "
"mode and queue for human approval before delivery."
)
chat = model.start_chat()
response = chat.send_message("Check my inbox and summarize what&"cm">#039;s new")
# Handle function calls
while response.candidates[0].content.parts[0].function_call:
fc = response.candidates[0].content.parts[0].function_call
result = execute_function(fc.name, fc.args)
response = chat.send_message(
genai.protos.Content(parts=[genai.protos.Part(
function_response=genai.protos.FunctionResponse(
name=fc.name, response={"result": result}
)
)])
)
print(response.text)Create a Gemini chat session with email tools and handle function calls against MultiMail.
"cm"># Define callable functions that Gemini can invoke automatically
def send_email(mailbox_id: str, to: str, subject: str, body: str) -> dict:
"""Send an email through MultiMail. In gated_send mode, queues for approval."""
resp = requests.post(f"{MULTIMAIL_API}/send", headers=MM_HEADERS, json={
"mailbox_id": mailbox_id, "to": to, "subject": subject, "body": body
})
return resp.json()
def check_inbox(mailbox_id: str, limit: int = 10) -> dict:
"""Check inbox for recent messages."""
resp = requests.get(
f"{MULTIMAIL_API}/mailboxes/{mailbox_id}/inbox",
headers=MM_HEADERS, params={"limit": limit}
)
return resp.json()
"cm"># Enable automatic function calling
model = genai.GenerativeModel(
model_name="gemini-2.0-flash",
tools=[send_email, check_inbox]
)
"cm"># The SDK automatically executes function calls and feeds results back
response = model.generate_content(
"Check inbox mbx_abc123 and draft a reply to the latest message",
tool_config={"function_calling_config": {"mode": "AUTO"}}
)
print(response.text)Use Gemini's automatic function calling to simplify the agent loop — the SDK handles tool execution.
Sign up at multimail.dev, create a mailbox, and generate an API key from your dashboard. Your key will start with mm_live_.
Install the Google Generative AI SDK and requests library for calling the MultiMail API.
pip install google-generativeai requestsCreate FunctionDeclaration objects for send_email, check_inbox, and other MultiMail operations using Gemini's typed schema format.
Initialize a GenerativeModel with your email tools and start a chat session. Send messages and handle function call responses in a loop.
model = genai.GenerativeModel(model_name="gemini-2.0-flash", tools=[email_tools])
chat = model.start_chat()If your mailbox uses gated_send mode (the default), review and approve pending emails in the MultiMail dashboard before they are delivered.
Email infrastructure built for AI agents. Verifiable identity, graduated oversight, and a 38-tool MCP server. Formally verified in Lean 4.