I am in the process of moving several applications from Websphere App server to
Tomcat. I've had an email function in my appolication for a long while with no trouble. Now, I have an intermittent problem occuring when I try to use JavaMail to send email. It works sometimes and not others. It appears to be related to system resources in some way because the problem arises after the server has been running for a few hours. I increased the heap size and the MaxPermSize, but there doesn't really seem to be a shortage in memory according to Lambda Probe. It still happens on and off. There are also a few other web apps running on this instance as well.
Below is the stack trace and the JavaMail code.
Please Help!
Matt
Properties props = System.getProperties();
props.put("mail.smtp.host", this.smtpServer);
Session session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(this.from));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(this.to));
msg.setSubject(this.subject);
msg.setText(this.body);
msg.setSentDate(new Date());
Transport.send(msg);
ERROR 2007-01-26 11:14:37,913 (ComplicatedEmail.java:send:125) - javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
nested exception is:
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:275)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at com.nuhorizons.rosettanet.www.ComplicatedEmail.send(ComplicatedEmail.java:112)
at com.nuhorizons.rosettanet.util.AlertEmailUtil.sendEmail(AlertEmailUtil.java:265)
at com.nuhorizons.rosettanet.util.AlertEmailUtil.sendDesignEmail(AlertEmailUtil.java:242)
at com.nuhorizons.rosettanet.util.AlertEmailUtil.send5C2SentSuccessfully(AlertEmailUtil.java:148)
at com.nuhorizons.rosettanet.controller.transmit.remote.RemoteRequestRegistrationTransmitter.sendSuccessAlert(RemoteRequestRegistrationTransmitter.java:150)
at com.nuhorizons.rosettanet.controller.transmit.remote.RemoteMessageTransmitter.doPost(RemoteMessageTransmitter.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.jstripe.tomcat.probe.Tomcat55AgentValve.invoke(Tomcat55AgentValve.java:20)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:507)
at java.net.Socket.connect(Socket.java:457)
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)
... 30 more