Ever stumbled across this?
javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.MessagingException: 501 5.0.0 HELO requires domain address
I wasn’t able for a long time to find the solution in the net although many people reported having this problem. The only hint you find is “There was an invalid entry in /etc/hosts”. But noone said exactly what the “invalid entry” was.
I myself found that there was no invalid entry but the configured hostname of the machine (issue “hostname” in a shell) cannot be resolved by DNS. The result is the given error message from the mail server.
What is happening? JavaMail resolves its own hostname by asking for the local hostname. The SMTP protocol requires the sending domain while handshaking. The server will try to resolve the domain by its DNS. If the hostname sent cannot be resolved then the server responds with “HELO requires domain address” as stated above.
I hope that this issue now becomes clearer to all of you.
PS: Solution is make sure your hostname can be resolved by DNS. Fix your hostname if it’s wrong or add the DNS entry.
2 replies on “JavaMail: Sending mails fails”
Hi Ralph, I am seeing similar exception javax.mail.MessagingException: 501 5.5.4 Invalid domain name. Would you know what this means?
I confirmed that the “hostname” command in the shell, resolves in the DNS. I double checked all the entries in /etc/hosts as well and they are all correct.
Thanks,
Abhinav
Hi Abhinav,
on mail client: check with ‘hostname -f’ the full-qualified domain name. This is (usually) the name the client transmits while handshaking.
Next check on mail server with ‘nslookup <fqdn>’ whether this name resolves.
If this check is successful then I recommend to sniff the communication in order to find out the hostname that the client transmits. It might be possible that the client doesn’t use the full hostname and so the server cannot verify it.