Send email via Python SMTP. Default: Gmail App Password (smtp.gmail.com:587, STARTTLS).
Setup
- •
Go to https://myaccount.google.com/apppasswords
- •Requires 2FA enabled on your Google account
- •Create a new app password (name it "OpenClaw" or similar)
- •Copy the 16-character password
- •
Add credentials to
~/.openclaw/.env:codeSMTP_USER=you@gmail.com SMTP_PASS=abcdefghijklmnop
- •
Verify:
bashpython3 {baseDir}/scripts/send_email.py \ --to you@gmail.com --subject "Test" --body "Hello" --dry-run
Usage
Basic send:
bash
python3 {baseDir}/scripts/send_email.py \
--to recipient@example.com \
--subject "Meeting tomorrow" \
--body "Hi, just confirming our meeting at 3pm."
HTML email:
bash
python3 {baseDir}/scripts/send_email.py \
--to recipient@example.com \
--subject "Report" \
--body "<h1>Monthly Report</h1><p>See attached.</p>" \
--html
With attachments:
bash
python3 {baseDir}/scripts/send_email.py \
--to recipient@example.com \
--subject "Files" \
--body "Please find attached." \
--attach /path/to/report.pdf \
--attach /path/to/data.csv
Multiple recipients with CC/BCC:
bash
python3 {baseDir}/scripts/send_email.py \
--to "a@example.com, b@example.com" \
--cc "manager@example.com" \
--bcc "archive@example.com" \
--subject "Update" \
--body "Team update for this week."
JSON output (for scripting):
bash
python3 {baseDir}/scripts/send_email.py \
--to a@example.com --subject "Hi" --body "Hello" --json
Custom SMTP server:
bash
python3 {baseDir}/scripts/send_email.py \
--host smtp.office365.com --port 587 \
--user me@company.com --password "xxx" \
--to colleague@company.com \
--subject "Note" --body "FYI"
Credentials
Resolution order (first match wins):
- •
--user/--passwordflags - •
SMTP_USER/SMTP_PASSenvironment variables - •
~/.openclaw/.envfile
Notes
- •Always confirm with the user before sending (especially to external recipients).
- •Use
--dry-runto preview the full MIME message without sending. - •Attachments are auto-detected for MIME type.
- •Gmail rate limit: ~500 emails/day for personal accounts.
- •Exit codes: 0=success, 1=validation error, 2=credential error, 3=SMTP error, 4=send error.