E-Mails aus Python senden, auf drei Wegen
Sende aus Python mit smtplib und dem Brevo SMTP-Relay, mit dem offiziellen Python SDK oder mit rohen HTTP-Requests an die Brevo REST API.

So funktioniert's
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}")
Ersetze API-Schlüssel, Absender und Empfänger durch deine eigenen. Bewahre Schlüssel in Umgebungsvariablen auf.
Frag deinen AI Agent
Prompts für den Brevo MCP-Server.
Bevor ich E-Mails aus meiner Python-App sende, prüfe, ob ich einen verifizierten Absender und eine authentifizierte Versanddomain habe. Liste auf, was fehlt.
Nur lesend: Er liest dein Brevo-Konto über den Brevo MCP-Server und ändert nichts.
Einrichtung in drei Schritten
Die richtigen Zugangsdaten holen
Authentifiziere zuerst deine Versanddomain und den Absender. Das SDK und rohes HTTP nutzen einen API-Schlüssel, den du unter SMTP & API, dann API keys & MCP erstellst. smtplib nutzt einen SMTP-Schlüssel aus dem Tab SMTP, nie einen API-Schlüssel.
Methode wählen und senden
Neues Projekt: pip install brevo-python, einen Brevo Client mit deinem api_key erstellen und client.transactional_emails.send_transac_email aufrufen. Vorhandener Code mit smtplib oder Framework: auf smtp-relay.brevo.com an Port 587 ausrichten. Kein SDK: per POST an /v3/smtp/email mit requests senden.
Fehler behandeln und das Log prüfen
Das SDK löst ApiError mit Statuscode und Body aus und wiederholt Requests standardmäßig mit Backoff. Bestätige die Zustellung unter Transactional, dann Email logs. Bewahre Schlüssel in Umgebungsvariablen auf.


