aspose file tools*
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
Author

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
Greenhorn

Joined: Feb 28, 2001
Posts: 21
Hello Mike,
Have you tried "mail.host" rather then "mail.smtp.host"? 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("mail.host", (String)config.get("mailServer"));
Session con = Session.getInstance(p, null);
Works for me.
Good Luck,
Craig
oops, didn't need html there..
------------------
SCJP2
[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 'esweb1.mydomain.com' 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
Greenhorn

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
Sheriff

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
Greenhorn

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...
dan
raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
Hi
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 ?

Thanks
T Michael
Greenhorn

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", "127.0.0.1");
It's obviously not the root of the problem but an acceptable workaround.

And for anyone still affected:
http://java.sun.com/products/javamail/FAQ.html#helo
http://weblogs.java.net/blog/2004/10/11/blarg8-stupid-user-trick-goggle-cache
http://jira.atlassian.com/browse/JRA-9892
Emilio de la Torre
Greenhorn

Joined: Feb 16, 2012
Posts: 4
Hi! Im having the same problem, but changing the mail.smtp.localhost to 127.0.0.1 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
Greenhorn

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("mail.smtp.host", "smtpserver.domain.com");
props.put("mail.smtp.localhost", "mypc.mydomain.com);
props.put("mail.smtp.auth", "true");

Session sesion = Session.getDefaultInstance(props);

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

msg.setFrom(new InternetAddress("from@domain.com"));

InternetAddress[] address = { new InternetAddress("to@domain.com") };

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


transport.connect(host, port, username, password);
transport.sendMessage(msg, msg.getRecipients(Message.RecipientType.TO));
transport.close();
} catch (MessagingException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JavaMail Exception "HELO requires domain address"