File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes JavaMail Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JavaMail Exception "HELO requires domain address"" Watch "JavaMail Exception "HELO requires domain address"" New topic

JavaMail Exception "HELO requires domain address"

Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

If you've seen this before, then all you'll need is the subject line, but here's some more details:
I don't think there's anything wrong with that code (aside from it's propensity to throw null pointers and/or arrayindexoutofbounds exceptions.

Running it produces:
the 501 response is from my mail provider, so I know it's not connectivity. Anything I can find on this response (God bless Google) indicates a problem with the DNS setup of the system I am trying to send email *from*.

So if I go to my Operations guy I want to be able to tell him I'm confident my code is not the problem, but currently I'm not sure where to point him. He doesn't know anything about how JavaMail works, and I don't know anything about configuring a Solaris box to play nice with the smtp provider.

Has anyone encountered this problem, and it's solution?
Craig O'Brien

Joined: Feb 28, 2001
Posts: 21
Hello Mike,
Have you tried "" rather then ""? I tried your setting and it appears to look for a local smtp server rather then a remote one.
Properties p = new Properties();
p.put("", (String)config.get("mailServer"));
Session con = Session.getInstance(p, null);
Works for me.
Good Luck,
oops, didn't need html there..
[This message has been edited by Craig O'Brien (edited December 20, 2001).]

Sun Certified Programmer for the Java 2 Platform<br />Senior Software Engineer<br />TechRx
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

That didn't help in my case.

I think it's a more fundamental problem than that. I connect to the provider, because the error message is from my smtp server.

the problem is.. from where does JavaMail get the name of the box that it is trying to send from?

If I use sendmail on this box, I can send to the same mail server with no problem, because in sendmail you can tell it to 'fake out' the DNS. You can tell sendmail to reply with '' when the smtp asks for it.

Where in JavaMail (what's the property?) do I tell it to reply with this value? Or is it even possible to tell JavaMail to fake out the domain of the sending box? (Does it get it from the DNS configuration of the box).

My Operations guy is in the process of getting this box name placed into DNS, which might take a few days, but in the meantime, I'm wondering if I can fake it, like you can with sendmail.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Downloading the source code for j2ee, I found inside the source of STMPTransport class, the following:So there's my answer for how JavaMail gets it.. it's from the InetAddress class. And Yes, it's possible to fake out the response by including a 'mail.smtp.localhost' property as in the following modified code from my first post...
[This message has been edited by Mike Curwen (edited December 20, 2001).]
suheel hussain

Joined: Nov 01, 2001
Posts: 16
just a dumb question: Is javax.mail package part of only j2ee? I could not locate mail
package in standard edition!
Michael Ernest
High Plains Drifter

Joined: Oct 25, 2000
Posts: 7292

Hi Suheel -
It's an unbundled extension you download separately. Here's the splash page if you wish.
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide

Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Or, if you download the j2sdkee j2ee.jar contains the Mail api classes.
Dan Heller

Joined: Nov 29, 2003
Posts: 1
Just a bit of extra info on this problem:
If you look at the code in the SMTPTransport class, it will cache the name of the localhost, so you'll need to make sure that your servlet container gets restarted if you change the value of the mail.smtp.localhost property to ensure that the SMTPTransport class gets reloaded (may or may not happen when your class is reloaded). This burned about an hour and a half of my time today...
raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
I have the same problem , How do you resolve it ?
I am using a remote machine as a mail server to send my emails ,
what should value of mail.smtp.localhost be ?
should i use the remote machine name / domain name in it or it should be my local machine the email sending java code is executing ?

T Michael

Joined: Nov 25, 2009
Posts: 2
I also had this one on CentOS5 and tomcat6.

I used Mike Curwen's solution, in my instance: props.put("mail.smtp.localhost", "");
It's obviously not the root of the problem but an acceptable workaround.

And for anyone still affected:
Emilio de la Torre

Joined: Feb 16, 2012
Posts: 4
Hi! Im having the same problem, but changing the mail.smtp.localhost to didnt work. I can send mails with the same code in a separate class, but when i try it in a class mounted on a Jboss i get the "Send helo first" error, any ideas. Thanks
Emilio de la Torre

Joined: Feb 16, 2012
Posts: 4
Always jumps "send hello first" error

props.put("mail.smtp.transport.protocol", "smtp");
props.put("mail.smtp.starttls.enable", "true");
props.put("", "");
props.put("mail.smtp.localhost", ";
props.put("mail.smtp.auth", "true");

Session sesion = Session.getDefaultInstance(props);

try {
Transport transport = sesion.getTransport("smtp");
MimeMessage msg = new MimeMessage(sesion);

msg.setFrom(new InternetAddress(""));

InternetAddress[] address = { new InternetAddress("") };

msg.addRecipients(Message.RecipientType.TO, address);
msg.setText("This is a test", "text/plain");

transport.connect(host, port, username, password);
transport.sendMessage(msg, msg.getRecipients(Message.RecipientType.TO));
} catch (MessagingException e) {
} catch (Exception e) {
I agree. Here's the link:
subject: JavaMail Exception "HELO requires domain address"
jQuery in Action, 3rd edition