SMTP: 504 5.5.2 <localhost>: Helo command rejected: need fully-qualified hostname
The receiving server refused your EHLO/HELO greeting because the name you sent is not a valid fully-qualified domain name.
Helo command rejected: need fully-qualified hostname504 5.5.2 Helo command rejectedHelo command rejected: Host not found501 5.5.4 Invalid domain name HELOHELO command rejected: invalid hostname Meaning
Servers with reject_non_fqdn_helo_hostname or reject_invalid_helo_hostname refuse names like localhost, a bare hostname, or an IP without brackets. Set your sender's name to a hostname with a matching A record and PTR, such as mail.example.com.
Common causes
- HELO is
localhostor a short hostname - Application using a default hostname from the container
- HELO name has no DNS record
- IP literal without square brackets
- Hostname differs from the PTR record
⚡ Quick fix
- Set a proper FQDN as the HELO name (
myhostnamein Postfix,local_hostnamein smtplib) - Make sure the FQDN has A and PTR records
- Containers: set the hostname explicitly
Detailed fix by platform
Postfix
postconf -e 'myhostname = mail.example.com' && postfix reload
Python
smtplib.SMTP("smtp.example.com", 587, local_hostname="mail.example.com")
How to diagnose
- HELO — Value sent?
- DNS — A and PTR exist?
- Config — hostname set explicitly?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- 421 4.7.0 Try again later (rate limited) SMTP: 421 4.7.0 Our system has detected an unusual rate of unsolicited mail originating from your IP address. Mail sent from your IP address has been temporarily rate limited
- 450 4.7.1 Greylisted, please try again later SMTP: 450 4.7.1 <user@example.com>: Recipient address rejected: Greylisted, see http://postgrey.schweikert.ch/help/example.com.html
- 550 5.7.25 PTR record required SMTP: 550-5.7.25 The IP address sending this message does not have a PTR record setup, or the corresponding forward DNS entry does not point to the sending IP
Most viewed in Email / SMTP
Other ways to find it
Where this error sits
Origin: Network. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026