An SMTP relay that accepts connections from anywhere with only a password is a target. Credentials leak through code repositories, logs and phishing, and once they are out an attacker can send spam in your name from any country. IP allowlisting adds a second condition: the connection must come from an address that you have approved. It is one of the simplest ways to reduce the damage of a leaked password, and when it is badly planned it is also one of the simplest ways to cause an outage, because the address that your application uses to reach the internet is not always the one you expect. This guide explains how allowlisting works for SMTP and API access, how it fits with authentication, how to find the correct outbound address in common environments, what to do with dynamic and shared addresses, how to change entries without downtime and how to troubleshoot refused connections.
Allowlisting and authentication together
The two controls answer different questions. Authentication proves who is connecting; allowlisting limits from where. A relay that relies only on IP trust (sometimes called IP-based relay) authorises any machine on an approved address, which may include other users of a shared network or an infected host. A relay that relies only on a password is exposed to credential theft. Combining them means that an attacker needs both the secret and a foothold on an approved network. Many providers offer this as an optional setting for SMTP credentials and API keys. See API key security, permissions and rotation and sending account security.
Find the address your server really uses
The source address a mail relay sees is the public address of the network edge that your traffic leaves through, not the private address of your server. Check it from the machine that sends:
# From the sending host: which public IP do outbound connections use?
curl -s https://ifconfig.me ; echo
curl -s https://api.ipify.org ; echo
# Compare with what the relay sees: check the connection log or error messageBe aware of what lies between your code and the relay:
| Environment | Outbound address | Allowlist advice |
|---|---|---|
| Single VPS or dedicated server | Its public IP | Allow that address |
| Cloud VM with elastic or static IP | The attached static address | Allow it; keep the static IP attached |
| Cloud VM with ephemeral IP | Changes on stop or restart | Reserve a static IP first |
| Private subnet behind a NAT gateway | The NAT gateway address | Allow the NAT address, which every host in that subnet shares |
| Serverless functions and containers | Often a large changing pool | Route through a NAT with a static IP, or use API keys without IP rules |
| Office or home network | ISP-assigned, may change | Ask for a static address, or use a VPN with a fixed exit |
| Hosted web app platform | Shared platform addresses | Check whether the platform offers fixed outbound IPs |
| IPv4 and IPv6 | Different addresses for each | Allow the one that your host uses, or both |
If your application can reach the relay over both IPv4 and IPv6, the address may differ depending on which is chosen. Test from the production environment, not from a developer laptop.
Setting up an allowlist
- Inventory the senders. List every application, server and job that sends mail through the account, and which environment each runs in.
- Find their public egress addresses as above, for production, staging and any batch job.
- Allow the narrowest ranges. A single address (
/32) is better than a whole network. Use ranges only if you control them. - Add entries before you enable enforcement. Some platforms let you run in a log-only mode first. If yours does not, add the entries, send a test from each system and then switch on enforcement.
- Use separate credentials per system with their own allowlists. A leaked key from one system then does not work from another.
- Document each entry: owner, purpose and date. Entries without an owner are never removed.
- Plan emergency access. Make sure that at least two administrators can change the list without needing to send mail through the same system.
Changing addresses without downtime
When you move a server or change a NAT address, add the new address to the allowlist first, move the application, confirm that mail flows and only then remove the old one. If an address must be removed immediately, because of a compromise, accept a short interruption and have a fallback route ready. Keep a calendar reminder for the renewal or release of cloud addresses. Put the list in version control or an infrastructure-as-code tool where the provider has an API, so that changes are reviewed and recorded.
Troubleshooting refused connections
| Symptom | Likely cause | What to check |
|---|---|---|
| Connection refused or timeout on port 587 | Firewall at your side or the provider side | Test with openssl s_client -starttls smtp -connect host:587; see SMTP test guide |
| 535 authentication failed from a new server | New server not in the allowlist, or wrong credential | Check the source IP the relay logged; see 535 authentication failed |
| Works from laptop, fails from production | Different egress address | Allow the production NAT address |
| Works for hours, then fails | Ephemeral cloud IP changed | Reserve a static address |
| Intermittent failures | Several NAT addresses or load-balanced egress | Allow all of them, or force a single route |
| Relay access denied | Sending without authentication from a non-approved address | Authenticate and allow the address; see relay access denied |
| API returns 403 from one region | API key restricted to specific addresses | Add the address or create a new key for that environment |
Also check for timeouts and TLS problems that look the same, see SMTP connection timeouts and TLS errors, and port choice in SMTP ports.
A note on sending IPs versus source IPs
Two different sets of addresses are easy to confuse. The source address is where your application connects from, and it is what an allowlist at the relay checks. The sending address is the IP that the relay uses when it delivers the message to the recipient's mail server, and it is what SPF, blocklists and reputation systems see. Allowlisting your application's address does nothing to change the sending address, and changing your sending IPs, for example by moving to a dedicated pool, does not require a change to the allowlist. Keep the two lists apart in your documentation so that nobody edits the wrong one during an incident. For the sending side, see dedicated vs shared IP.
Monitoring and alerts
Treat refused connections as a signal. A sudden run of attempts from an address you do not know may mean that a credential has leaked and someone is testing it. Ask your provider whether failed attempts are logged and whether you can receive alerts, and review the log after any change to the list. Pair this with alerts on sending volume so that an unusual spike is noticed within minutes, not days.
What allowlisting does not protect
- An attacker who already controls a machine on the approved network.
- Applications on shared platforms where many tenants use the same outbound address.
- Messages sent through your own user mailboxes by phishing, where the attacker uses a normal mail client and the provider's interface.
- Misuse by your own code, such as a contact form that can be abused to send to anyone. Rate-limit and validate it.
Use allowlisting as one layer. Pair it with least-privilege keys, separate credentials per system, rotation, alerting on unusual sending volume and a plan for responding to compromise. A leaked credential that cannot be used from outside your network is a very different incident from one that can.
Restrict access to your sending account Create scoped credentials and limit them to the addresses you trust.
References and further reading
Frequently asked questions
What is SMTP IP allowlisting?
A control that accepts SMTP or API requests only from approved source IP addresses, usually in addition to a username and password or API key.
Is IP allowlisting enough on its own?
No. Combine it with authentication so that a host on an approved address cannot send without credentials.
Why does my allowlisted server still get refused?
Its outbound public address may differ from the one you allowed, for example because of a NAT gateway or an IPv6 address.
How do I allowlist serverless functions?
Route their outbound traffic through a NAT gateway with a static IP, or use scoped API keys with other protections.
How do I change allowlist entries safely?
Add the new address first, move the application, verify, then remove the old entry.