Self-Host an SMTP Relay on Cloudflare Workers (Open Source)
A free, open-source SMTP relay on Cloudflare Workers: what the Send As relay does, the one-click deploy, the secrets it needs, ports and what it never stores.
The Send As Team
4 min read
The Send As relay is a small open-source Cloudflare Worker that turns an authenticated HTTPS request from your browser into an SMTP send through your own mail host. You deploy it into your own Cloudflare account with one button, so we never host it or see its secrets. This guide covers what it does and what it needs.
You only need it if your mailbox offers SMTP and no API, such as cPanel or GoDaddy email. Gmail’s “Send mail as” for non-Google addresses ends in January 2027 (Google’s notice), which is why people reach for one.
Why does SMTP need a relay at all?
Browser extensions can make HTTPS requests but cannot open raw SMTP connections. A Worker can, using Cloudflare’s outbound sockets. So the chain is: the extension calls your relay over HTTPS with a secret, the relay connects to your SMTP server and sends. If you use one of the four API providers instead, no relay is needed; see Resend, Postmark, SendGrid and Mailgun.
What the relay does and does not do
- It is stateless: no database, no storage, no logs of messages, subjects or recipients.
- It accepts only requests carrying your relay secret.
- It only sends as the addresses in
ALLOWED_FROM; anything else is refused. - With
starttls, if your server doesn’t offer STARTTLS, it stops before sending your password and never falls back to plain text. - Optionally it adds a copy to Gmail’s Sent Mail over IMAP.
Its configuration has Cloudflare’s Worker observability off and its code uses no console output. Cloudflare, as your host, still handles the traffic under its own terms, and you control Worker logging in your own account.
How do I deploy it?
- Create a free Cloudflare account. The free Workers plan is enough for personal volume, but check Cloudflare’s current limits.
- Press Deploy to Cloudflare in the relay docs. Cloudflare copies the relay into a repository in your GitHub account and deploys it to your Cloudflare account.
- Fill in the settings when asked. Anything not offered can be added later under your Worker’s Settings, Variables and Secrets; use Secret for passwords.
- Note the Worker’s address, for example
https://sendas-relay.your-subdomain.workers.dev. - In the extension, add an address, choose My own relay, enter the URL and the relay secret, and run Test & save.
Prefer the command line? The manual setup guide has a wrangler route that skips the GitHub copy.
What secrets does it need?
| Name | Required | What it is |
|---|---|---|
RELAY_SECRET |
Yes | A long random string (32+ characters) the extension sends with every request |
SMTP_HOST |
Yes | Your SMTP server, such as mail.yourbiz.com |
SMTP_PORT |
Yes | 465 or 587 (2465 and 2525 also work) |
SMTP_SECURITY |
Yes | tls for implicit TLS, starttls for 587 and 2525 |
SMTP_USER |
Yes | The SMTP login, usually the full address |
SMTP_PASS |
Yes | The SMTP password, preferably an app password or SMTP key; store as a secret |
ALLOWED_FROM |
Yes | Comma-separated addresses the relay may send as |
GMAIL_ADDRESS |
No | Your Gmail address, for the optional IMAP copy |
GMAIL_APP_PASSWORD |
No | A Gmail app password; store as a secret |
IMAP_HOST |
No | IMAP server for the copy; blank means Gmail |
Look up your host’s values in the SMTP presets. Use an app password where the provider offers one, not your main password. Note that a Gmail app password reaches your whole mailbox over IMAP, which is why the default copy is a BCC plus a filter, described in the filter docs.
Which ports work?
Use 465 with tls or 587 with starttls; 2465 and 2525 are also accepted. Port 25 doesn’t work on Workers, so a host that offers only 25 can’t be used. A port and security mismatch is the most common failure, and 465 with tls is the first thing to try. For the differences, see port 465 vs 587 vs 2525.
How do I check it works?
From a terminal, curl the Worker’s root address: it should say ok. Then call /v1/info with Authorization: Bearer YOUR_RELAY_SECRET; it shows your SMTP host, never the password. A wrong secret returns Unauthorized.
| Symptom | Likely cause |
|---|---|
| Unauthorized | The extension’s relay secret doesn’t match the Worker’s |
| 535 rejected | Wrong user or password, or a main password where an app password is needed |
| Timeout | Wrong host or port, or the host blocks Cloudflare |
| Sender not allowed | The From address isn’t in ALLOWED_FROM |
How do I update, rotate or delete it?
- Update: pull upstream changes in your GitHub copy and Cloudflare redeploys.
- Rotate: change
RELAY_SECRETin the Worker and in the extension. - Delete: remove the Worker under Workers & Pages; its secrets go with it.
- Revoke access: change the mailbox password at your host.
What are the trade-offs?
You own the maintenance: updates, rotation and Cloudflare billing questions. Whoever can open your Cloudflare account can read the SMTP secrets. In return, no Send As server is in the path. If you’d rather not maintain a Worker, the hosted Send As relay is the other option, with a different privacy trade-off (compared here).
When is the hosted relay or an API key simpler?
A relay is the right tool only when your mail host forces SMTP. If you can use Resend, Postmark, SendGrid or Mailgun, the extension talks to them directly and you skip the Worker. If you don’t want to maintain anything, the hosted relay does the work for you, at the privacy cost of a server we run in the path.
What to do next
Deploy from the relay docs, then follow the setup guide. Before you start, install the extension.
Frequently asked questions
What does the Send As relay do?
It is a small open-source Worker that receives an authenticated HTTPS request from the extension and sends the message to your SMTP server. Browsers can't open SMTP connections, so SMTP-only hosts need a relay.
Which ports does the relay support?
465 with implicit TLS, and 587 with STARTTLS. Ports 2465 and 2525 also work. Port 25 does not work because Cloudflare Workers can't use it, so hosts that only offer 25 can't be used with this relay.
Does the relay store or log my emails?
No. It has no database or storage and its code writes nothing. Cloudflare's Worker logging is turned off in its configuration, and you control that setting in your own account.
What secrets does the relay need?
RELAY_SECRET, SMTP_HOST, SMTP_PORT, SMTP_SECURITY, SMTP_USER, SMTP_PASS and ALLOWED_FROM are required. GMAIL_ADDRESS, GMAIL_APP_PASSWORD and IMAP_HOST are optional and only used for saving a copy into Gmail's Sent folder.
Keep reading
What Is an SMTP Relay? A Plain-English Explanation
What is an SMTP relay? Plain-English guide: how it works, why browsers cannot speak SMTP, relay vs API, and why your own relay keeps credentials private.
4 min read
SMTP Port 465 vs 587 vs 2525: Which to Use
SMTP port 465 vs 587 explained: implicit TLS vs STARTTLS, where 2525 fits, why port 25 fails on Cloudflare Workers, and how to fix 535 login errors.
4 min read
Are SMTP Passwords Safe in a Browser Extension? Send As
Are your SMTP passwords safe in a browser extension? How Send As encrypts keys with a passphrase, limits Gmail's page, and what it cannot protect you from.
4 min read