• Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaMail - Bizarre Issue - Connection Closed

 
Mark Garland
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

This issue seems bizarre - and I'm really hoping that someone who understands this a little more can point me in the right direction.

In short, I want my Linux server running Glassfish to email me on the hour (or there abouts). The Timer code is working fine.
My hosting provider (wiserhosting) tells me that port 465 is for smtp over ssl (as I understand it, NOT ssmpt).

Below is the code I have written for the emailer.
This code works absolutely perfectly - all day - no trouble at all. As long as another machine on the network is also on which runs Windows and is using Outlook to poll the mailbox periodically. As soon as the other Windows machine is switched off, the Linux box fails to send the next hourly email.

It's almost as if the Windows machine is doing some of the handshaking with the email server, then the Linux Glassfish server (which will appear to be the same IP externally from the perspective of wiserhosting's mail server) sneaks in on it's coattails (think of the windows server opening the door, then the linux server calling through that door). Then, when the Windows machine isn't holding that door open, the Linux server can no longer communicate through the door, and I get "Connection closed by remote host".

That's my hunch anyway. Code and Stacktrace below. Suggestions welcome - what have I misunderstood? Why can't my code establish it's own connection?!

Thanks in advance,

MG




Log Entry Detail - Not here in a 'code' block as it crashes the browser.

Timestamp

May 12, 2009 16:00:11.765
Log Level

SEVERE
Logger

vaultmonitor.EmailerBean
Name-Value Pairs

_ThreadID=228;_ThreadName=p: thread-pool-1; w: 308;_RequestID=55a46915-29ca-4523-b721-c5e313e69fe9;
Record Number

2213
Message ID

The log message is null. javax.mail.MessagingException
Complete Message

Can't send command to SMTP host; nested exception is: java.net.SocketException: Connection closed by remote host at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:1564) at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:1551) at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:696) at javax.mail.Transport.send0(Transport.java:191) at javax.mail.Transport.send(Transport.java:118) at vaultmonitor.EmailerBean.sendEmail(EmailerBean.java:61) at sun.reflect.GeneratedMethodAccessor3042.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1067) at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:176) at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2895) at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:3986) at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:197) at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:83) at $Proxy248.sendEmail(Unknown Source) at vaultmonitor.HeartBeatMonitorBean.doHeartBeat(HeartBeatMonitorBean.java:34) at sun.reflect.GeneratedMethodAccessor3043.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1067) at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:176) at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2895) at com.sun.ejb.containers.BaseContainer.callEJBTimeout(BaseContainer.java:2824) at com.sun.ejb.containers.EJBTimerService.deliverTimeout(EJBTimerService.java:1401) at com.sun.ejb.containers.EJBTimerService.access$100(EJBTimerService.java:99) at com.sun.ejb.containers.EJBTimerService$TaskExpiredWork.run(EJBTimerService.java:1952) at com.sun.ejb.containers.EJBTimerService$TaskExpiredWork.service(EJBTimerService.java:1948) at com.sun.ejb.containers.util.WorkAdapter.doWork(WorkAdapter.java:75) at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555) Caused by: java.net.SocketException: Connection closed by remote host at sun.security.ssl.SSLSocketImpl.checkWrite(SSLSocketImpl.java:1273) at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:62) at com.sun.mail.util.TraceOutputStream.write(TraceOutputStream.java:114) at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140) at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:1562) ... 29 more

 
Mark Garland
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like we have a stumper!
 
Mark Garland
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Got it to work!! If you look at the timestamps you'll realise it too me sometime to get round to it.

Changing the protocol from smtp to smtps seemed to do it.
Not entirely sure how you'd achieve that with the below code, but I followed this to get it working within Glassfish v3. Setting up the resource via the Container is a better way to go anyway.

I'll hope it still works tomorrow when I try it again, but so far, so good!

Thanks,

MG
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!