wood burning stoves 2.0*
The moose likes Other JSE/JEE APIs and the fly likes Could not connect to SMTP host: localhost, port: 25 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Could not connect to SMTP host: localhost, port: 25" Watch "Could not connect to SMTP host: localhost, port: 25" New topic
Author

Could not connect to SMTP host: localhost, port: 25

Matthew McHale
Greenhorn

Joined: Jan 26, 2007
Posts: 1
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
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41137
    
  45
Welcome to JavaRanch.

This line: "java.net.ConnectException: Connection refused: connect" leads me to believe that the problem might be on the server side. Have you checked the server logs to see if there is anything untoward happening?


Ping & DNS - my free Android networking tools app
rajanikanth bhagavan kanth
Ranch Hand

Joined: May 20, 2008
Posts: 78
I'm also getting the same error.
Can any one please respond to this mail

Regards,
Bhagavan R
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41137
    
  45
Do you have an SMTP server running on localhost? If so, check its log files for messages. If not, then that's your problem.
[ December 08, 2008: Message edited by: Ulf Dittmer ]
rajanikanth bhagavan kanth
Ranch Hand

Joined: May 20, 2008
Posts: 78
Yes, in my localhost SMTP server is running sucessfully i didn't get any error messages.But my application gives that error message.

Let me know if im not clear.

Regards,
Bhagavan R
L Ganesh
Ranch Hand

Joined: Jul 10, 2008
Posts: 30
I am also getting the same error
can anyone please help me
i have tried with a different mail client and my ports and server is fine.


Ganesh
SCJP 1.6
Varun Padival
Greenhorn

Joined: Dec 09, 2010
Posts: 2
Was there any resolution for this issues. I am also facing the same problem as Matthew.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41137
    
  45
The question is the same:
Do you have an SMTP server running on localhost on port 25? If so, check its log files for messages. If not, then that's your problem.
Varun Padival
Greenhorn

Joined: Dec 09, 2010
Posts: 2
We have email server on different machine and its running on prot 25.

The problem we are getting is that the mails will be working for some days. After some days suddenly the mails will not be sent and if we check the log we see the error messages as "Could not connect to the mail server : port 25". After we restart the tomcat the emails will start working again.

Are there any configurations/logs where we can check exactly what the problem was

Thanks,
Varun Padival
Paul Okeke
Ranch Hand

Joined: May 16, 2009
Posts: 58
I think I have a related problem but I was able to solve mine problem half way by eliminating the but still my sent Mail so not yet delivered to the desired destination.
How I solved it:



But my unfortunate thing is that my mail is not delivered after successful sending.


OCJP 1.6
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

How do you know the mail is not delivered? Have you checked the server where you are sending it to?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Paul Okeke, please stick to your own thread for this. Don't hijack other people's threads.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Paul Okeke
Ranch Hand

Joined: May 16, 2009
Posts: 58
Rob Prime, I don't know that it is an offense Posting what I felt will assist Matthew McHale if not solve his situation.
I felt we are all here to help each other, Matthew McHale has almost the same problem as I do.
In my case, I have already gotten some solutions which I felt will help Matthew McHale if not solving his own problem totally.

I post my Apologies.......................
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Matthew hasn't been here since 2007, so I doubt he will read this. But I have misread your post somewhat, so I too apologize for being somewhat harsh.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Could not connect to SMTP host: localhost, port: 25
 
Similar Threads
how to send mail using gmail server
SMTP connection error - Sun Application Server
Could not connect to SMTP host: smtp.bizmail.yahoo.com, port: 25
Could not open connection to the host, on port 25: Connect Failed.
how to solve Below error?