Skip to content

Send email over SMTP

Send transactional emails over Cloudflare Email Service SMTP using curl, Nodemailer, Python smtplib, or PHPMailer.

Send transactional emails over Cloudflare Email Service authenticated SMTP (smtp.mx.cloudflare.net:465) from any SMTP-capable language or client.

Prerequisites

  • A domain onboarded for Email Sending.
  • A Cloudflare API token with the Email Sending: Edit permission. Set it as CF_API_TOKEN in your environment. The token is used as the SMTP password; the username is the literal string api_token.

Send an email

Terminal window
cat > mail.txt <<EOF
From: welcome@yourdomain.com
To: recipient@example.com
Subject: Welcome to our service!
Thanks for signing up.
EOF
curl --ssl-reqd \
--url "smtps://smtp.mx.cloudflare.net:465" \
--user "api_token:$CF_API_TOKEN" \
--mail-from "welcome@yourdomain.com" \
--mail-rcpt "recipient@example.com" \
--upload-file mail.txt

The sender domain must be onboarded for Email Sending on the account that owns the API token.

Next steps

  • SMTP reference — connection details, authentication, response codes, and troubleshooting.
  • Specify recipients — multiple recipients, CC and BCC, and named addresses.
  • Limits — account, message, and session limits.