users@glassfish.java.net

Re: Glassfish and JavaMail

From: Sahoo <Sahoo_at_Sun.COM>
Date: Thu, 27 Dec 2007 20:54:43 +0530

Couple of ways to do this:

1. Define a resource ref in your web.xml file, name the resource
reference as "mail/seg", supply its type as javax.mail.Session.
  Map the resource reference to the actual name "seg" using sun-web.xml
file. Now ic.lookup("java:comp/env/mail/seg") would return Session object.

Or,
2. If you are using Java EE 5, you can inject a Session in your servlet
or filter or listener or ejb using the following syntax:
    @Resource(name="mail/seg", mappedName="seg")
    Session mailSession; // inject the Mail Session named seg


Hope this helps. For more information, read the Java EE platform spec
(chapter 5 , I think).

Thanks,
Sahoo

glassfish_at_javadesktop.org wrote:
> Hello,
>
> I have createad a Java Mail Session from glassfish admin console named seg.
>
> As in the example I execute:
>
> String snName = "java:comp/env/mail/seg";
> Object ref = ic.lookup(snName);
>
> But everytime it will not find the object. I will get:
> javax.naming.NameNotFoundException: No object bound to name java:comp/env/mail/seg
>
> however if I only lookup for seg, it will find, but not a javax.mail.Session object but rather: com.sun.enterprise.deployment.MailConfiguration
>
> Could someone explain the proper way? Is there a bug or misconfiguration?
>
> Best,
> [Message sent by forum member 'segfault2007' (segfault2007)]
>
> http://forums.java.net/jive/thread.jspa?messageID=251516
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>