Hi, I'm having trouble sending mail with Apache Commons Email in Tomcat 6.0. At the top of the stack trace the mail server I'm sending to (that is known to be working ok) is mentioned but further down the trace there are _Caused by_ messages mentioning problems sending to localhost.
It seems like the hostname that I'm setting via Commons Emails's .setHostName(...) is getting lost somewhere and javax.mail... falls back to localhost. This code works fine when run as a JUnit test. Does anyone have an idea about what may be causing this loss of mail host name when run with Tomcat? Here's the stacktrace (actual mail host name replaced with "some.mail.server ") Cause: Sending the email to the following server failed : some.mail.server:25 org.apache.commons.mail.EmailException: Sending the email to the following server failed : some.mail.server:25 at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1138) at org.apache.commons.mail.Email.send(Email.java:1163) <snip> Caused by: javax.mail.SendFailedException: Send failure ( javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25 (java.net.ConnectException: Connection refused: connect)) at javax.mail.Transport.send(Transport.java:163) at javax.mail.Transport.send(Transport.java:48) at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1128) ... 14 more Caused by: javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25 (java.net.ConnectException: Connection refused: connect) at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1282) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370) at javax.mail.Service.connect(Service.java:231) at javax.mail.Service.connect(Service.java:85) at javax.mail.Service.connect(Service.java:70) at javax.mail.Transport.send(Transport.java:94) ... 16 more Caused by: java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(Unknown Source) at java.net.PlainSocketImpl.connectToAddress(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:232) at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189) at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1250) ... 21 more Thanks for any hints. /Björn -- Björn Þór Jónsson http://bthj.is
