← All Guides
How to Send Emails with Python
Send transactional emails from your Python application using AISend's REST API. Works with Django, Flask, FastAPI, or any Python project.
1. Install the SDK
Install the AISend Python package:
pip install aisend2. Send an email
Use the AISend client to send your first email:
from aisend import AISend
client = AISend(api_key="as_your_api_key")
result = client.emails.send(
from_email="hello@yourdomain.com",
to="user@example.com",
subject="Hello from Python",
html="<p>Sent with AISend from Python.</p>"
)
print(result)3. Using with Flask
Example Flask endpoint for sending emails:
from flask import Flask, request, jsonify
from aisend import AISend
app = Flask(__name__)
client = AISend(api_key="as_your_api_key")
@app.route("/send", methods=["POST"])
def send_email():
data = request.json
result = client.emails.send(
from_email="hello@yourdomain.com",
to=data["to"],
subject=data["subject"],
html=data["html"],
)
return jsonify(result)4. Using with cURL (no SDK needed)
You can also call the API directly:
curl -X POST https://api.aisend.app/v1/emails \
-H "Authorization: Bearer as_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"from": "hello@yourdomain.com",
"to": "user@example.com",
"subject": "Hello",
"html": "<p>Sent with AISend.</p>"
}'