A lightweight Python SMTP server that receives emails and forwards their content to Datadog's logs API.
Perfect for monitoring application emails, or creating email-based logging pipelines.
# Create virtual environment and install dependencies
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# Start the server
DATADOG_API_KEY=your_api_key_here python3 smtp2datadog.py
# In another terminal, send a test email
python3 send_test_email.py- Asynchronous SMTP server using aiosmtpd
- Parses incoming emails (subject, body, headers)
- Sends structured logs to Datadog Logs API
- Configurable via environment variables
- Handles both plain text and multipart emails
- Test script included
-
Clone this repository
-
Create a virtual environment and install dependencies:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtConfiguration is done via environment variables:
DATADOG_API_KEY: Your Datadog API key (required)DATADOG_SITE: Your Datadog site (default: datadoghq.com)- US1:
datadoghq.com - US3:
us3.datadoghq.com - US5:
us5.datadoghq.com - EU:
datadoghq.eu - AP1:
ap1.datadoghq.com
- US1:
SERVICE_NAME: Service name for tagging logs (default: smtp2datadog)SMTP_HOST: Host to bind the SMTP server (default: localhost)SMTP_PORT: Port for the SMTP server (default: 1025)
See .env.example for reference.
Linux/macOS:
# Export environment variable
export DATADOG_API_KEY=your_api_key_here
python3 smtp2datadog.py
# Or inline
DATADOG_API_KEY=your_api_key_here python3 smtp2datadog.pyWindows (Command Prompt):
set DATADOG_API_KEY=your_api_key_here
python smtp2datadog.pyWindows (PowerShell):
$env:DATADOG_API_KEY="your_api_key_here"
python smtp2datadog.pyUse the included test script:
python3 send_test_email.pyOr send emails manually using the swaks tool:
swaks --to test@example.com \
--from sender@example.com \
--server localhost:1025 \
--header "Subject: Test Email" \
--body "This is a test message"Emails are sent to Datadog with the following structure:
{
"ddsource": "smtp",
"ddtags": "service:smtp2datadog,env:production",
"hostname": "client-hostname",
"message": "Email from sender@example.com: Subject Line",
"email": {
"from": "sender@example.com",
"to": "recipient@example.com",
"subject": "Subject Line",
"body": "Email body content",
"date": "Mon, 25 Oct 2025 12:00:00 +0000",
"recipients": ["recipient@example.com"],
"mail_from": "sender@example.com"
},
"timestamp": "2025-10-25T12:00:00.000000Z"
}- Go to Datadog Logs Explorer
- Filter by
source:smtporservice:smtp2datadog - You can create custom facets on the
email.*fields for better filtering
This server has NO authentication.
- By default, the server binds to
localhostand is only accessible from the local machine
- Converting application emails to Datadog logs for centralized monitoring
MIT