Email Tools

Send an email from an agent with EmailTools configured with sender credentials and a receiver.

email_tools.py
"""
Email Tools
=============================

Demonstrates email tools.
"""

from agno.agent import Agent
from agno.tools.email import EmailTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------


receiver_email = "<receiver_email>"
sender_email = "<sender_email>"
sender_name = "<sender_name>"
sender_passkey = "<sender_passkey>"

# Example 1: Enable specific email functions
agent = Agent(
    tools=[
        EmailTools(
            receiver_email=receiver_email,
            sender_email=sender_email,
            sender_name=sender_name,
            sender_passkey=sender_passkey,
            enable_email_user=True,
        )
    ]
)

# Example 2: Enable all email functions
agent_all = Agent(
    tools=[
        EmailTools(
            receiver_email=receiver_email,
            sender_email=sender_email,
            sender_name=sender_name,
            sender_passkey=sender_passkey,
            all=True,
        )
    ]
)

# Test the agent

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    agent.print_response(
        "Send an email to the receiver with subject 'Test Email' and a friendly greeting message",
        markdown=True,
    )

Configure the Gmail sender

Replace all four placeholders with your sender address, sender name, sender credential, and your own test recipient. This toolkit connects specifically to smtp.gmail.com:465 with SSL; it does not accept a custom SMTP host. Use a Gmail app password where your account permits it, rather than an ordinary account password. The agent's run can send a real message.

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno openai

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

Run the example

Save the code above as email_tools.py, then run:

python email_tools.py

Full source: cookbook/91_tools/email_tools.py