JavaMail + MailConfiguration cannot be cast to javax.mail.Session

If you’re trying out JavaMail with JavaEE (6) on Glassfish and get a ClassCastException like these SEVERE: java.lang.ClassCastException: com.sun.enterprise.deployment.MailConfiguration cannot be cast to javax.mail.Session javax.faces.el.EvaluationException: java.lang.ClassCastException: com.sun.enterprise.deployment.MailConfiguration cannot be cast to javax.mail.Session at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) at javax.faces.component.UICommand.broadcast(UICommand.java:315) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:774) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1266) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:310) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1522) … when trying […]