Email

Send email through Gmail SMTP with EmailTools.

EmailTools sends email through Gmail SMTP.

Prerequisites

  1. Enable 2-Step Verification for the sender's Google Account.
  2. Create a Gmail app password.
  3. Install Agno and the OpenAI client:

This example requires a Google Account that supports app passwords. Google may withhold app passwords from work, school, or organization accounts, security-key-only 2-Step Verification accounts, and accounts enrolled in Advanced Protection.

uv pip install -U "agno[openai]"

Set the sender, receiver, app password, and model provider API key:

export RECEIVER_EMAIL="receiver@example.com"
export SENDER_EMAIL="sender@gmail.com"
export SENDER_NAME="Agno Agent"
export GMAIL_APP_PASSWORD="your_gmail_app_password"
export OPENAI_API_KEY="your_openai_api_key_here"

Example

cookbook/91_tools/email_tools.py
from os import getenv

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

receiver_email = getenv("RECEIVER_EMAIL")
sender_email = getenv("SENDER_EMAIL")
sender_name = getenv("SENDER_NAME")
sender_passkey = getenv("GMAIL_APP_PASSWORD")

agent = Agent(
    tools=[
        EmailTools(
            receiver_email=receiver_email,
            sender_email=sender_email,
            sender_name=sender_name,
            sender_passkey=sender_passkey,
        )
    ]
)

agent.print_response("Send an email confirming that the report is ready.")

Toolkit Params

ParameterTypeDefaultDescription
receiver_emailOptional[str]NoneThe email address of the receiver.
sender_nameOptional[str]NoneThe name of the sender.
sender_emailOptional[str]NoneThe email address of the sender.
sender_passkeyOptional[str]NoneThe Gmail app password for the sender.
enable_email_userboolTrueEnable the email_user function.
allboolFalseEnable all available functions.

Toolkit Functions

FunctionDescription
email_userEmails the user with the given subject and body. Parameters include subject (str) for the email subject and body (str) for the email content. Currently works with Gmail. Returns "email sent successfully" or error message.

Developer Resources