Reputation: 102773
We found out today that for two of our customers, JavaMail is not authenticating and so our product can't send email. We have been sending emails through our own server for years, as well as for several other customers, and we thought we were using authentication for all of those.
The code proceeds as follows:
transport = session.getTransport("smtp");
transport.connect(hostName, port, user, password);
According to the documentation here, JavaMail should be using authentication if we used this form of the connect() method. We aren't setting any properties, but if I'm reading that page properly, we don't need to.
We are using the mail.jar out of JBoss 4.2.1.GA.
What do we need to do differently?
Update: if I use the other method on that documentation page (setting mail.smtp.auth property and providing an Authenticator), authentication finally works. But what were we doing wrong with this method?
Upvotes: 3
Views: 1480
Reputation: 102773
I finally discovered that I was calling:
transport.send(message, message.getAllRecipients());
, which is a static method, instead of:
transport.sendMessage(message, message.getAllRecipients());
I think this is why it wasn't authenticating, so I think this is the real answer. Would've helped if I'd posted that piece of code, but I had no idea that was where the problem was. Can't for the life of me figure out why Transport.send() is a static method, but if you know, please tell me.
Upvotes: 1
Reputation: 31903
Try props.put("mail.debug", "true");
for possible debug info which will give you more insight.
In addition, if this is a Windows box, have a look for firewall or anti-virus running: http://forums.sun.com/thread.jspa?threadID=590866
Upvotes: 2