wood burning stoves 2.0*
The moose likes Java in General and the fly likes MessagingException: IOException while sending message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "MessagingException: IOException while sending message" Watch "MessagingException: IOException while sending message" New topic
Author

MessagingException: IOException while sending message

Bushra Binte
Ranch Hand

Joined: Nov 07, 2006
Posts: 60
Hi,I get the below error while trying to send an email using java mail API.The same code when i run from desktop is working fine.But when i deploy it on the server as a war file,i get the below error

javax.mail.MessagingException: IOException while sending message;
nested exception is:
java.io.FileNotFoundException: /Error_20080825.xls (No such file or directory)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:676)
at javax.mail.Transport.send0(Transport.java:189)
at javax.mail.Transport.send(Transport.java:118)
at et911.services.MailService.postMailWithAttachment(MailService.java:112)
at et911.orders.bodys.BodyUploadFile.sendAsEmail(BodyUploadFile.java:320)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:146)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:92)
at com.sun.rave.web.ui.appbase.faces.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
at javax.faces.component.UICommand.broadcast(UICommand.java:332)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:287)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:401)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:95)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:245)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:110)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:213)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.sun.rave.web.ui.util.UploadFilter.doFilter(UploadFilter.java:215)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)
could someone please help
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Where is Error_20080825.xls stored?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Bushra Binte
Ranch Hand

Joined: Nov 07, 2006
Posts: 60
It is stored on the server,where the application is deployed.
i get this error when execute transport.send() line of code.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

OK, you have to make sure the path to teh file is corerct. Currently it is looking for it at
/Error_20080825.xls
, which is clearly not the location of the file on your filesystem. You will need to give it an absolute path or a relative path.
Bushra Binte
Ranch Hand

Joined: Nov 07, 2006
Posts: 60
I tried,n found that we are using getRealPath() of ServletContext.in jsf.I used the method getContext.
Now i set relative path starting from context root of the application.Still i get "file or directory not found" exception when deployed in the unix box.
here is the path framed at runtime: /TTest/resources/uploads/testdels.xls

here is the error msg:

java.io.IOException: No such file or directory
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:850)
at et911.services.UploadService.setFileType(UploadService.java:94)
at et911.services.UploadService.readUploadedFile(UploadService.java:78)
at et911.orders.bodys.BodyUploadFile.uploadFileBtn_action(BodyUploadFile.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:146)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:92)
at com.sun.rave.web.ui.appbase.faces.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
at javax.faces.component.UICommand.broadcast(UICommand.java:332)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:287)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:401)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:95)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:245)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:110)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:213)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.sun.rave.web.ui.util.UploadFilter.doFilter(UploadFilter.java:215)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

After retrieving what you think is the correct path (after using getRealPath()), what does the following print (with file being the name for the file):

Something tells me that the path is still not 100% correct, and with that little piece of code you can see what the path currently is. That will help you fix it.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Bushra Binte
Ranch Hand

Joined: Nov 07, 2006
Posts: 60
getRealPath(),is working in windows but not in SunOS 5.10
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

What version of the JDK are you using?
Bushra Binte
Ranch Hand

Joined: Nov 07, 2006
Posts: 60
Its JDK5
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

1.) What error/exception does it return?

2.) Have you tried Rob's suggestion?

3.) If you can try JDK 6 then do so, it might have a fix for getRealPath() if it is truly broken, the very latest JDK 5 (_17) might do the trick as well.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

Martijn Verburg wrote:3.) If you can try JDK 6 then do so, it might have a fix for getRealPath() if it is truly broken, the very latest JDK 5 (_17) might do the trick as well.

getRealPath() is not in JSE - it's specified by JEE and nearly always implemented by the web container (Tomcat, Websphere, etc) developers.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

My apologies, that's what you get for being lazy and not looking it up!
Bushra Binte
Ranch Hand

Joined: Nov 07, 2006
Posts: 60
You know what,the variable that was holding the path to the file was instanse variable.i made it a class variable and resolved the problem.

Now the name of the attachment file sent in email has the path as its name.can we any way change the name of the attachment file.
Its a FileOutputStream object.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

How do you add the attachment? Using a separate Part, with the contents set using setDataHandler(new DataHandler(new FileDataSource(file)))?
If so, you can simply call setFileName on the same Part.
Bushra Binte
Ranch Hand

Joined: Nov 07, 2006
Posts: 60
hey..thats what i found,we can set the name of the attachment using setFileName().Thanks.
 
 
subject: MessagingException: IOException while sending message