# SMTP: 504 5.5.2 <localhost>: Helo command rejected: need fully-qualified hostname

**Code:** `Helo command rejected: need fully-qualified hostname` · **Category:** Email / SMTP · **Seen on:** SMTP, Linux

The receiving server refused your EHLO/HELO greeting because the name you sent is not a valid fully-qualified domain name.

## 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 `localhost` or 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

1. Set a proper FQDN as the HELO name (`myhostname` in Postfix, `local_hostname` in smtplib)
2. Make sure the FQDN has A and PTR records
3. Containers: set the hostname explicitly

## Detailed fix by platform

### Postfix

1. `postconf -e 'myhostname = mail.example.com' && postfix reload`

### Python

1. `smtplib.SMTP("smtp.example.com", 587, local_hostname="mail.example.com")`

## How to diagnose

1. **HELO** — Value sent?
2. **DNS** — A and PTR exist?
3. **Config** — hostname set explicitly?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/email/smtp-ehlo-helo-rejected)
