Send email from Python, three ways
Send from Python with smtplib and the Brevo SMTP relay, with the official Python SDK, or with raw HTTP requests to the Brevo REST API.

How it works
pip install brevo-python
from brevo import Brevo
from brevo.transactional_emails import (
SendTransacEmailRequestSender,
SendTransacEmailRequestToItem,
)
client = Brevo(api_key="your-api-key")
result = client.transactional_emails.send_transac_email(
subject="Hello from Brevo!",
html_content="<html><body><p>Hello,</p><p>This is my first transactional email.</p></body></html>",
sender=SendTransacEmailRequestSender(
name="Alex from Brevo",
email="[email protected]",
),
to=[
SendTransacEmailRequestToItem(
email="[email protected]",
name="John Doe",
)
],
)
print("Email sent. Message ID:", result.message_id)
import asyncio
from brevo import AsyncBrevo
from brevo.transactional_emails import (
SendTransacEmailRequestSender,
SendTransacEmailRequestToItem,
)
client = AsyncBrevo(api_key="your-api-key")
async def main() -> None:
result = await client.transactional_emails.send_transac_email(
subject="Hello from Brevo!",
html_content="<html><body><p>Hello!</p></body></html>",
sender=SendTransacEmailRequestSender(
name="Alex from Brevo",
email="[email protected]",
),
to=[
SendTransacEmailRequestToItem(
email="[email protected]",
name="John Doe",
)
],
)
print("Email sent. Message ID:", result.message_id)
asyncio.run(main())
from brevo import Brevo
from brevo.core.api_error import ApiError
client = Brevo(api_key="your-api-key")
try:
client.transactional_emails.send_transac_email(...)
except ApiError as e:
print(e.status_code)
print(e.body)
import smtplib
from email.message import EmailMessage
SMTP_SERVER = "smtp-relay.brevo.com"
SMTP_PORT = 587
SMTP_LOGIN = "[email protected]" # Your SMTP login (Brevo, SMTP & API, SMTP tab)
SMTP_KEY = "YOUR_SMTP_KEY" # SMTP key, not your API key
msg = EmailMessage()
msg["Subject"] = "Your subject line here"
msg["From"] = "[email protected]"
msg["To"] = "[email protected]"
msg.set_content("Hello, this is a plain text email sent via Brevo SMTP.")
with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
server.starttls() # Upgrade to a secure connection (TLS)
server.login(SMTP_LOGIN, SMTP_KEY)
server.send_message(msg)
print("Sent!")
import requests
import json
import os
API_KEY = os.environ["BREVO_API_KEY"]
payload = {
"sender": {"email": "[email protected]", "name": "My App"},
"to": [{"email": "[email protected]", "name": "User"}],
"subject": "Welcome to My App!",
"htmlContent": "<html><body><h1>Hello!</h1></body></html>"
}
response = requests.post(
"https://api.brevo.com/v3/smtp/email",
headers={"api-key": API_KEY, "Content-Type": "application/json"},
data=json.dumps(payload)
)
if response.status_code == 201:
print("Sent! Message ID:", response.json()["messageId"])
elif response.status_code == 429:
retry_after = response.headers.get("Retry-After", "60")
print(f"Rate limit. Retry after {retry_after}s")
else:
print(f"Error {response.status_code}: {response.text}")
Replace the API key, sender and recipient with your own. Keep keys in environment variables.
Ask your AI agent
Prompts for the Brevo MCP server.
Before I send email from my Python app, check that I have a verified sender and an authenticated sending domain. List what is missing.
Read-only: it reads your Brevo account through the Brevo MCP server and changes nothing.
Setup in three steps
Get the right credential
Authenticate your sending domain and sender first. The SDK and raw HTTP use an API key, created under SMTP & API, then API keys & MCP. smtplib uses an SMTP key from the SMTP tab, never an API key.
Pick a method and send
New project: pip install brevo-python, create a Brevo client with your api_key and call client.transactional_emails.send_transac_email. Existing smtplib or framework code: point it at smtp-relay.brevo.com on port 587. No SDK: post to /v3/smtp/email with requests.
Handle errors and check the log
The SDK raises ApiError with a status code and body, and retries with backoff by default. Confirm delivery under Transactional, then Email logs. Keep keys in environment variables.


