users@glassfish.java.net

Help with JavaMail

From: David Salter <david_at_davidsalter.com>
Date: Fri, 01 Jun 2007 01:58:57 -0700

Hi,

I've configured a JavaMail Session within Glassfish and caled it
"glassfishmail" to test it out. I'm trying to use this from within an
EJB that I am accessing via a web service. My code is pretty much like
below, but I get a class cast exception thrown.

@Stateless()
@WebService()
public class EmailTest {
@WebMethod
...
InitialContext ctx = new InitialContext();
Session session = (Session).lookup("glassfishmail"); //
ClassCastException thrown here.
Message msg = new MimeMessage(session);
...

From what I've read, I'm guessing that I need to specify a res-ref
within my sun-ejb-jar.xml file. If this is correct, does anyone have
an example of what I need? Also, can this be done via annotations
rather than xml?

I also suspect that I need to look up
"java:comp/env/mail/glassfishmail", but this gives me a
NameNotFoundException.

Any help much appreciated.


Thanks in advance,

Dave.