Invalid HELO name in JavaMail

2020-04-21 08:09发布

问题:

I'm getting the following error when using JavaMail to send mails. Its unusual because its been working for sometime until now and no changes have been made.

 550 Access denied - Invalid HELO name (See RFC2821 4.1.1.1)
com.sun.mail.smtp.SMTPSendFailedException: 550 Access denied - Invalid HELO name (See RFC2821 4.1.1.1)

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)

I have take a look at the RFC doc but unsre how to translate its meaning to the JavaMail properties.

Any ideas why and any solutions are appreciated.

回答1:

From JavaMail API FAQ:

Q: I get "MessagingException: 501 HELO requires domain address" when trying to send a message. A: The SMTP provider uses the results of InetAddress.getLocalHost().getHostName() in the SMTP HELO command. If that call fails to return any data, no name is sent in the HELO command. Check your JDK and name server configuration to ensure that that call returns the correct data. You may also set the "mail.smtp.localhost" property to the name you want to use for the HELO command.

It's not the exact same error message but that shouldn't make a difference for your case.

So just make sure to set it to something your mail server accepts. Check docs, config or your local postmaster as I can't tell you what that is. Probably you're just sending "localhost" which is denied. Try setting it to a hostname that actually resolves to your IP address (if possible).