Remote mail servers judge you by the address your connection comes from. Not the address you meant to use, not the address in your documentation, but the one that actually appears in the packets. On a simple server with one address this is trivial. On a machine with several addresses, behind NAT, in a cloud network with a gateway or in a container cluster, it is surprisingly easy to send from the wrong one. The consequences are practical: SPF fails because the address is not listed, the PTR record does not match, a reputation that took months to build is bypassed or an unwarmed address suddenly carries your volume. This guide explains how the source address is chosen, how to control it in common mail servers and applications, how NAT and cloud gateways change the picture and how to verify the result. It builds on FCrDNS, IP pools and firewall rules for email.
How the source address is chosen
When a program opens an outgoing TCP connection without specifying a source address, the operating system picks one according to the routing table: normally the primary address of the interface that leads toward the destination. On a host with several addresses on one interface, that is usually the first one assigned (or, on IPv6, one chosen by the address selection rules, which prefer a stable address of the same scope). In a network with NAT, the address the remote server sees is not the host address at all but the gateway's public address, which may be shared with many other machines. These are separate layers:
| Layer | Who decides | Control |
|---|---|---|
| Application | The program may bind to a specific local address before connecting | MTA settings such as smtp_bind_address; application socket options |
| Operating system | Chooses a source address for unbound sockets by route and policy | Routing tables, policy routing, address labels, IPv6 selection rules |
| NAT or cloud gateway | Rewrites the source to a public address | Gateway or elastic IP configuration, NAT rules |
| Provider network | May block or rewrite traffic | Provider documentation; some providers require registration of sending IPs |
Binding in common mail servers
| Server | How to set the source address | Notes |
|---|---|---|
| Postfix (global) | smtp_bind_address = 203.0.113.25 and smtp_bind_address6 = 2001:db8::25 in main.cf | Applies to all outgoing SMTP; also set myhostname to the matching name |
| Postfix (per transport) | Define extra transports in master.cf with -o smtp_bind_address=203.0.113.26 and route domains with transport_maps or sender-dependent maps | Lets different senders or domains use different IPs. See IP pools |
| Exim | Set interface on the remote_smtp transport (can be a list or expansion based on the sender) | Combine with a distinct helo_data for each address |
| Sendmail | Use the ClientPortOptions with Addr= and the DaemonPortOptions for inbound | Check the documentation for the version in use |
| Microsoft Exchange | Choose the send connector source servers; on a multi-IP server set the connector's source bindings | Use the host's outgoing address selection for fine control |
| Applications (Python, Java, Node) | Pass a source address to the socket or SMTP client constructor (for example source_address in smtplib) | Remember IPv4 and IPv6 separately |
| Managed relays | Select an IP pool, dedicated address or sender identity in the provider configuration | You normally do not bind addresses yourself |
# Postfix: all outgoing mail from one address (main.cf)
myhostname = mail1.example.com
smtp_bind_address = 203.0.113.25
smtp_bind_address6 = 2001:db8::25
# Postfix: a second transport for marketing mail (master.cf)
smtp-mkt unix - - n - - smtp
-o smtp_bind_address=203.0.113.26
-o smtp_helo_name=mail2.example.com
# main.cf
transport_maps = hash:/etc/postfix/transport
# /etc/postfix/transport
news.example.com smtp-mkt:NAT, cloud gateways and containers
- The public address belongs to the gateway. Your server may have a private address, but remote servers see the NAT address. SPF, PTR and reputation concern that public address.
- Shared NAT addresses mix reputations. If the gateway also serves web crawlers, user machines or other tenants, anything they do affects the address your mail uses. Give mail its own public address.
- Several public addresses on a gateway: select the address per source host with source NAT rules, so that each mail server uses its own.
- Cloud elastic or reserved IPs are attached to an instance or a NAT gateway; make sure the correct one is used for outbound traffic, and that reverse DNS is configured for it. Some clouds select the outbound address differently for instances with a public IP and for those behind a NAT gateway.
- Containers and clusters: pods may leave through any node. Pin mail workloads to specific nodes or an egress gateway with a fixed address.
- Failover changes the address. If a standby takes over with a different public IP, SPF and PTR must already cover it, and its reputation must be warmed. See disaster recovery planning.
Consequences of the wrong address
| Symptom | Cause | Fix |
|---|---|---|
| SPF fail for your own mail | The sending address is not in the SPF record | Add the correct address or bind to the listed one. See SPF |
| Receivers complain about reverse DNS or HELO mismatch | The visible address has a different PTR than your EHLO name | Align PTR, A record and EHLO per address. See HELO errors |
| Sudden poor delivery to a major provider | Mail left from an unwarmed or shared address | Check which address was used and route correctly. See warm-up |
| Blocklist listing for an address you do not use for mail | Another service behind the same NAT sent spam | Isolate mail on its own address; request delisting. See delisting |
| Different addresses for IPv4 and IPv6 | Dual-stack host picks IPv6 while only IPv4 is prepared | Prepare both or disable IPv6 outbound. See IPv6 sending |
| A customer cannot allowlist you | Addresses change without notice | Use a dedicated pool and announce changes |
Verification
- Send a test message to a mailbox you control at an external provider.
- Open the source and read the topmost Received header of the receiving system: it records the address that connected. See reading Received headers.
- Check the Authentication-Results header for the SPF result and the address shown. See authentication results.
- Look at your own mail log for the relay line and, on the sender, the local bind address in connection logs.
- From the server, run
curl -s https://ifconfig.meor a similar service (if egress to it is allowed) to see the general outbound address, then confirm for port 25 with a connection to a test SMTP service you control. - Repeat for IPv6, and for each transport and domain you route differently.
- Add the check to your change routine and after any network or cloud change.
Documentation table
| IP | PTR / EHLO name | Purpose | State | In SPF |
|---|---|---|---|---|
| 203.0.113.25 | mail1.example.com | Transactional | Warm, in production | Yes (ip4) |
| 203.0.113.26 | mail2.example.com | Marketing | Warming (week 3) | Yes (ip4) |
| 2001:db8::25 | mail1.example.com | Transactional (IPv6) | Not in use | No |
| 203.0.113.30 | mail9.example.com | Reserve for failover | Warm-up planned | Yes (ip4) |
Keep this table with your runbook, review it when anything changes and make sure monitoring alerts if mail leaves from an address outside it. The sending address is a small detail until it is wrong, and then it is the first thing everyone asks about.
Check the address you send from Look for blocklist listings and DNS problems.
References and further reading
Frequently asked questions
How do I choose which IP address Postfix sends from?
Set smtp_bind_address and smtp_bind_address6 in main.cf, or define per-transport values in master.cf.
Why does my mail show a different IP than my server address?
NAT or a cloud gateway rewrites the source, so remote servers see the gateway public address.
What happens if the source IP is not in my SPF record?
SPF fails for that message, which can cause spam placement or rejection and DMARC failure if DKIM does not pass.
How can I confirm the address that remote servers see?
Send a test message to an external mailbox and read the topmost Received header and the SPF result.
Should mail share a NAT address with other services?
No. Give mail a dedicated public address so unrelated traffic cannot damage its reputation.