Prerequisites
Before sending, verify your domain and create an SMTP credential. Use a sandbox credential for these examples so no email is delivered. Keep the username and password in your server’s secret store. Before you begin, ensure you have:System Requirements
System Requirements
- Python installed on your system (Download Python)
- a supported Python 3 release (recommended)
- Basic knowledge of Python programming
Built-in Modules
Python’s standard library includes everything you need for SMTP:smtplib Module
Purpose: SMTP client session object
Features: Connection, authentication, sending
Security: STARTTLS support
Import:
Features: Connection, authentication, sending
Security: STARTTLS support
Import:
import smtplibemail Module
Purpose: Email message construction
Features: MIME, attachments, HTML
Classes: EmailMessage, MIMEMultipart
Import:
Features: MIME, attachments, HTML
Classes: EmailMessage, MIMEMultipart
Import:
from email.message import EmailMessageConnection Settings
All message data is stored in the EU. See SMTP limits.
Basic Email Examples
Testing with Sandbox Mode
Use sandbox mode to safely test your Python email integration:Sandbox Benefits: Emails sent in sandbox mode are free, trigger webhooks normally, and never actually deliver to recipients - perfect for development and testing.
Environment Variables & Best Practices
Using Environment Variables
smtplib with environment variables
Resources
Python smtplib Documentation
Official Python smtplib module documentation
Python email Documentation
Official Python email module documentation
Python.org
Official Python programming language documentation
AhaSend Support
Get help from our engineering team
Related Guides
- Before sending: verify your domain and create an SMTP credential.
- Connection and message rules: SMTP hosts, ports and limits, special headers, sandbox mode, retention and plan features.
- Other ways to send: REST API, AhaSend CLI, Node.js SDK and Go SDK.
- Delivery events: webhook setup and local webhook testing.

