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?
Joined: Feb 28, 2001
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
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.
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).]
Joined: Nov 01, 2001
just a dumb question: Is javax.mail package part of only j2ee? I could not locate mail package in standard edition!
Or, if you download the j2sdkee j2ee.jar contains the Mail api classes.
Joined: Nov 29, 2003
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
Joined: Jul 14, 2005
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 ?
Joined: Nov 25, 2009
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.
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