Send email through Gmail SMTP with EmailTools.
EmailTools sends email through Gmail SMTP.
Prerequisites
- Enable 2-Step Verification for the sender's Google Account.
- Create a Gmail app password.
- 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
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
| Parameter | Type | Default | Description |
|---|---|---|---|
receiver_email | Optional[str] | None | The email address of the receiver. |
sender_name | Optional[str] | None | The name of the sender. |
sender_email | Optional[str] | None | The email address of the sender. |
sender_passkey | Optional[str] | None | The Gmail app password for the sender. |
enable_email_user | bool | True | Enable the email_user function. |
all | bool | False | Enable all available functions. |
Toolkit Functions
| Function | Description |
|---|---|
email_user | Emails 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. |