When your Postfix server attempts to deliver email to certain domains, you might encounter this rejection:
504 5.5.2 <contact@localhost>: Sender address rejected: need fully-qualified address
This occurs because some strict mail servers require sender addresses to use proper FQDNs (Fully Qualified Domain Names) rather than localhost or unqualified hostnames.
Here are the essential Postfix configuration changes you need to make in /etc/postfix/main.cf
:
# Set your actual mail domain
myorigin = yourdomain.com
# Force FQDN in sender addresses
sender_canonical_maps = regexp:/etc/postfix/sender_canonical
# Default transport maps (if not already set)
transport_maps = hash:/etc/postfix/transport
Create /etc/postfix/sender_canonical
with this content:
/^.*@localhost$/ contact@yourdomain.com
/^.*@hostname$/ contact@yourdomain.com
Then compile the map:
sudo postmap /etc/postfix/sender_canonical
These parameters help ensure proper FQDN usage:
# Set your mail server's FQDN
myhostname = mail.yourdomain.com
# Important for HELO/EHLO
smtp_helo_name = mail.yourdomain.com
# Prevent localhost in headers
masquerade_domains = yourdomain.com
After making changes, always test:
sudo postfix check
sudo postfix reload
You can verify the sender address behavior with:
echo "Test" | mail -s "Test Subject" external@example.com
- Check
/var/log/mail.log
for any remaining issues - Use
postconf -n
to verify your active settings - Test with strict mail servers like Gmail or Outlook
When Postfix attempts to send emails to certain domains, you might encounter the rejection error indicating the sender address isn't fully-qualified. This happens because remote SMTP servers enforce RFC compliance, requiring sender addresses in the format user@domain.tld
rather than user@localhost
.
The root cause typically lies in these Postfix settings:
# Main configuration file: /etc/postfix/main.cf
myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
When these aren't properly configured, Postfix defaults to using localhost
as the domain part.
Here's how to properly configure Postfix for FQDN compliance:
# Edit main.cf
sudo nano /etc/postfix/main.cf
# Set these parameters:
myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
inet_interfaces = all
For complex setups with multiple domains, use sender canonical maps:
# /etc/postfix/sender_canonical_maps
@localhost contact@yourdomain.com
@hostname contact@yourdomain.com
# Add to main.cf:
sender_canonical_maps = hash:/etc/postfix/sender_canonical_maps
# Then compile the map:
sudo postmap /etc/postfix/sender_canonical_maps
After making changes, verify with:
sudo postfix check
sudo postfix reload
echo "Test email" | mail -s "Test" recipient@example.com
Check your mail logs to confirm the sender address appears correctly:
tail -f /var/log/mail.log
- Ensure your DNS has valid MX records
- Verify reverse DNS matches your hostname
- Check for conflicting settings in master.cf