1 Reply Latest reply on Jul 9, 2009 3:57 AM by Nikolay Elenkov

    Catch SMTPSendFailedException

    Alex Cougarman Apprentice

      We're getting an SMTPSendFailedException exception from time to time on our server. Here's the method to send emails in Seam:


      public void sendEmail() {
        status = "Processing email now...";
      
        try {
          renderer.render("/mail.xhtml");
          status = "Email sent successfully."; 
        }
        catch (javax.faces.FacesException e) {
          status = "An error occurred while sending the email: " + e.getMessage();
        }
        finally {
          renderer = null;
        }
      }



      Here's the exception we see from time to time:     


      2009-07-07 15:16:52,486 INFO  [STDOUT] 451 4.3.2 Please try again later
      2009-07-07 15:16:52,490 INFO  [STDOUT] com.sun.mail.smtp.SMTPSendFailedException: 451 4.3.2 Please try again later
      2009-07-07 15:16:52,491 INFO  [STDOUT]     at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
      2009-07-07 15:16:52,492 INFO  [STDOUT]     at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1215)
      2009-07-07 15:16:52,492 INFO  [STDOUT]     at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:586)
      2009-07-07 15:16:52,492 INFO  [STDOUT]     at org.jboss.seam.mail.ui.UIMessage.encodeEnd(UIMessage.java:168)
      2009-07-07 15:16:52,492 INFO  [STDOUT]     at org.jboss.seam.ui.util.JSF.renderChild(JSF.java:181)
      2009-07-07 15:16:52,492 INFO  [STDOUT]     at org.jboss.seam.ui.util.JSF.renderChildren(JSF.java:163)
      2009-07-07 15:16:52,492 INFO  [STDOUT]     at org.jboss.seam.ui.facelet.RendererRequest.renderFacelet(RendererRequest.java:103)
      2009-07-07 15:16:52,493 INFO  [STDOUT]     at org.jboss.seam.ui.facelet.RendererRequest.run(RendererRequest.java:73)
      2009-07-07 15:16:52,493 INFO  [STDOUT]     at org.jboss.seam.ui.facelet.FaceletsRenderer.render(FaceletsRenderer.java:43)
      2009-07-07 15:16:52,493 INFO  [STDOUT]     at org.unctv.formsnewemployee.session.NewEmployeeAction.sendEmail(NewEmployeeAction.java:52)
      2009-07-07 15:16:52,493 INFO  [STDOUT]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2009-07-07 15:16:52,493 INFO  [STDOUT]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      2009-07-07 15:16:52,493 INFO  [STDOUT]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      2009-07-07 15:16:52,494 INFO  [STDOUT]     at java.lang.reflect.Method.invoke(Method.java:585)
      2009-07-07 15:16:52,494 INFO  [STDOUT]     at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
      2009-07-07 15:16:52,494 INFO  [STDOUT]     at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
      2009-07-07 15:16:52,494 INFO  [STDOUT]     at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
      2009-07-07 15:16:52,494 INFO  [STDOUT]     at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
      2009-07-07 15:16:52,494 INFO  [STDOUT]     at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      2009-07-07 15:16:52,495 INFO  [STDOUT]     at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
      2009-07-07 15:16:52,495 INFO  [STDOUT]     at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      2009-07-07 15:16:52,495 INFO  [STDOUT]     at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
      2009-07-07 15:16:52,495 INFO  [STDOUT]     at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      2009-07-07 15:16:52,495 INFO  [STDOUT]     at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
      2009-07-07 15:16:52,495 INFO  [STDOUT]     at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
      2009-07-07 15:16:52,496 INFO  [STDOUT]     at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
      2009-07-07 15:16:52,496 INFO  [STDOUT]     at org.unctv.formsnewemployee.session.NewEmployeeAction_$$_javassist_1.sendEmail(NewEmployeeAction_$$_javassist_1.java)
      2009-07-07 15:16:52,496 INFO  [STDOUT]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2009-07-07 15:16:52,496 INFO  [STDOUT]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      2009-07-07 15:16:52,496 INFO  [STDOUT]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      2009-07-07 15:16:52,496 INFO  [STDOUT]     at java.lang.reflect.Method.invoke(Method.java:585)
      2009-07-07 15:16:52,497 INFO  [STDOUT]     at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329)
      2009-07-07 15:16:52,497 INFO  [STDOUT]     at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:274)
      2009-07-07 15:16:52,497 INFO  [STDOUT]     at org.jboss.el.parser.AstMethodSuffix.getValue(AstMethodSuffix.java:59)
      2009-07-07 15:16:52,497 INFO  [STDOUT]     at org.jboss.el.parser.AstMethodSuffix.invoke(AstMethodSuffix.java:65)
      2009-07-07 15:16:52,497 INFO  [STDOUT]     at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
      2009-07-07 15:16:52,497 INFO  [STDOUT]     at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
      2009-07-07 15:16:52,498 INFO  [STDOUT]     at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
      2009-07-07 15:16:52,498 INFO  [STDOUT]     at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
      2009-07-07 15:16:52,498 INFO  [STDOUT]     at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
      2009-07-07 15:16:52,498 INFO  [STDOUT]     at javax.faces.component.UICommand.broadcast(UICommand.java:383)
      2009-07-07 15:16:52,498 INFO  [STDOUT]     at org.ajax4jsf.component.AjaxActionComponent.broadcast(AjaxActionComponent.java:55)
      2009-07-07 15:16:52,498 INFO  [STDOUT]     at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
      2009-07-07 15:16:52,499 INFO  [STDOUT]     at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
      2009-07-07 15:16:52,499 INFO  [STDOUT]     at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
      2009-07-07 15:16:52,499 INFO  [STDOUT]     at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
      2009-07-07 15:16:52,499 INFO  [STDOUT]     at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
      2009-07-07 15:16:52,499 INFO  [STDOUT]     at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
      2009-07-07 15:16:52,499 INFO  [STDOUT]     at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
      2009-07-07 15:16:52,500 INFO  [STDOUT]     at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
      2009-07-07 15:16:52,500 INFO  [STDOUT]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      2009-07-07 15:16:52,500 INFO  [STDOUT]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      2009-07-07 15:16:52,500 INFO  [STDOUT]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
      2009-07-07 15:16:52,500 INFO  [STDOUT]     at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
      2009-07-07 15:16:52,500 INFO  [STDOUT]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      2009-07-07 15:16:52,501 INFO  [STDOUT]     at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
      2009-07-07 15:16:52,501 INFO  [STDOUT]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      2009-07-07 15:16:52,501 INFO  [STDOUT]     at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
      2009-07-07 15:16:52,501 INFO  [STDOUT]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      2009-07-07 15:16:52,501 INFO  [STDOUT]     at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
      2009-07-07 15:16:52,501 INFO  [STDOUT]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      2009-07-07 15:16:52,502 INFO  [STDOUT]     at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
      2009-07-07 15:16:52,502 INFO  [STDOUT]     at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
      2009-07-07 15:16:52,502 INFO  [STDOUT]     at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
      2009-07-07 15:16:52,502 INFO  [STDOUT]     at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
      2009-07-07 15:16:52,502 INFO  [STDOUT]     at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
      2009-07-07 15:16:52,502 INFO  [STDOUT]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      2009-07-07 15:16:52,503 INFO  [STDOUT]     at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
      2009-07-07 15:16:52,503 INFO  [STDOUT]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      2009-07-07 15:16:52,503 INFO  [STDOUT]     at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
      2009-07-07 15:16:52,503 INFO  [STDOUT]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      2009-07-07 15:16:52,503 INFO  [STDOUT]     at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
      2009-07-07 15:16:52,503 INFO  [STDOUT]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      2009-07-07 15:16:52,504 INFO  [STDOUT]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      2009-07-07 15:16:52,504 INFO  [STDOUT]     at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      2009-07-07 15:16:52,504 INFO  [STDOUT]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      2009-07-07 15:16:52,504 INFO  [STDOUT]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      2009-07-07 15:16:52,504 INFO  [STDOUT]     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      2009-07-07 15:16:52,504 INFO  [STDOUT]     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      2009-07-07 15:16:52,505 INFO  [STDOUT]     at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
      2009-07-07 15:16:52,505 INFO  [STDOUT]     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
      2009-07-07 15:16:52,505 INFO  [STDOUT]     at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      2009-07-07 15:16:52,505 INFO  [STDOUT]     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      2009-07-07 15:16:52,505 INFO  [STDOUT]     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
      2009-07-07 15:16:52,505 INFO  [STDOUT]     at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      2009-07-07 15:16:52,506 INFO  [STDOUT]     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      2009-07-07 15:16:52,506 INFO  [STDOUT]     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
      2009-07-07 15:16:52,506 INFO  [STDOUT]     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      2009-07-07 15:16:52,506 INFO  [STDOUT]     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
      2009-07-07 15:16:52,506 INFO  [STDOUT]     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      2009-07-07 15:16:52,506 INFO  [STDOUT]     at java.lang.Thread.run(Thread.java:595)



      Our server admin said that there is a limit to the number of sendmail child processes that can be run on any mail relay. When the mail relay stops accepting new connections, this will happen. This is to be expected, especially with the spam volumes we are seeing.


      I'd like to catch this exception and retry the delivery a certain number of times before giving up. However, when I try to put a Try/Catch for the SMTPSendFailedException, I get the error:


      Unreachable catch block for SMTPSendFailedException. This exception is never thrown from the try statement body



      How do I trap the SMTPSendFailedException exception and retry the send a few more times before quitting and displaying an error to the user? Thanks.