App emails failing on a cloud server? Port 25 is probably blocked
Short answer: If your app sends email perfectly on your laptop but times out on a new cloud server, the provider is probably blocking outgoing port 25, the port mail servers use to talk to each other. Google Cloud blocks it to external destinations, AWS restricts it by default, and some hosts block the usual submission ports too. The fix isn't to fight the block: send through an email provider's authenticated SMTP on port 587 or 465, or its HTTPS API, with your domain's SPF and DKIM set up.
Why cloud providers block port 25
Port 25 is how mail servers deliver messages to each other across the internet. It's also what spammers use when they rent cheap servers or compromise someone else's. Cloud providers block or limit it so their address ranges don't end up on blocklists, which would hurt every customer.
What their documentation says:
- Google Cloud: Compute Engine's guide on sending mail states that, due to the risk of abuse, connections to destination TCP port 25 are blocked when the destination is outside your network. It says traffic to external addresses on ports 587 or 465 is allowed by default unless your own firewall rules block it.
- AWS: the EC2 documentation lists a restriction on email sent using port 25 among default account limits, and explains that you can request its removal.
- DigitalOcean: its support documentation says SMTP ports 25, 465 and 587 are blocked on Droplets by default to prevent spam and abuse.
Other hosts have their own policies, so check yours. The pattern is the same: direct delivery from a fresh cloud server is discouraged.
Recognising the problem
- Sending hangs and then fails with a connection timeout, rather than an authentication or rejection error.
- Logs show attempts to connect to a remote mail server or relay on port 25.
- The same code and settings work from your office or laptop.
- A quick test from the server, such as
nc -vz smtp.example.com 25, times out while the same test on port 587 connects.
The better setup: authenticated submission
Mail clients and apps aren't supposed to deliver on port 25 anyway. The mail standards separate two jobs:
- Relay between mail servers on port 25.
- Message submission from clients and apps to a mail server, normally on port 587, as described in RFC 6409. RFC 8314 also defines port 465 for submission with TLS from the first byte ("implicit TLS").
So the right configuration for an app is to submit mail to an email service you have an account with:
- Choose a provider: your business email platform's SMTP service or a transactional email service built for app notifications.
- Use port 587 with STARTTLS or port 465 with implicit TLS, and the username and password or API key the provider gives you.
- Set up your domain: add the provider to your SPF record and publish its DKIM keys, then add a DMARC policy.
- Send a test to a few mailbox providers and check the headers show the message passed authentication.
Or use an HTTPS API
Most transactional email services also offer an API over HTTPS. It avoids SMTP ports entirely, works on hosts that block all mail ports, and usually gives you clearer error messages, delivery events and bounce data. Many frameworks have drivers for the common providers, so switching is often a configuration change.
When you really want your own mail server
Some businesses run their own mail server deliberately. If that's you:
- Request removal of the port 25 restriction through your provider's process, where one exists, and expect to explain your use.
- Set reverse DNS for the server's address to a proper hostname that resolves back.
- Publish SPF, DKIM and DMARC records, and monitor blocklists.
- Expect to spend time on deliverability. A new IP has no reputation and large mailbox providers are cautious.
For most small businesses, a managed email service is far less work and more reliable.
Testing before you rely on it
Once the new setup is in place, test the messages that matter most, not just a "hello" email. Trigger a password reset, an order confirmation and a contact-form notification, and check each arrives at a few different mailbox providers. Look at the full headers for passing SPF, DKIM and DMARC results. Then keep a simple automated check, such as a daily test message to a monitored inbox, so a future server move or expired credential doesn't silently stop mail again.
Common mistakes
- Using port 25 in app settings out of habit. Many tutorials do. Switch to 587 or 465.
- Hard-coding a personal mailbox password in the app. Use a dedicated sending account or API key, stored as a secret.
- Forgetting the From domain. Messages sent "from" your domain through a provider that isn't in your SPF or DKIM setup are likely to be filtered.
- No error logging. If email silently fails, customers miss confirmations and password resets. Log failures and alert on them.
A worked example
Take a hypothetical Liverpool joinery firm whose quote-request form emailed the office from a small cloud server. After moving to a new host, enquiries simply stopped arriving. The app's log showed timeouts connecting to a mail server on port 25, which the new host blocked. Their developer signed up for a transactional email service, switched the app to its API, added the service to the domain's SPF record and published its DKIM keys. Enquiries arrived again, and failed sends now raise an alert.
FAQ
Can I just use a different port to reach another server's port 25?
No. The receiving mail server listens where it listens. Use your provider's submission ports or API instead.
Is port 465 outdated?
No. RFC 8314 recommends implicit TLS on port 465 for submission. Both 465 and 587 are widely supported.
Why does it work on my laptop?
Home and office connections may allow port 25, or your laptop may already use an authenticated mail service.
Will this fix emails going to spam?
Sending through a reputable provider with SPF, DKIM and DMARC helps a lot, but content and recipient engagement matter too.
If your app's emails have stopped arriving since a server move, tell us how it sends mail and we'll help set it up properly.