applicationname/META-INF/context.xml

<Context reloadable="true">
<Resource name="mail/session" auth="Container" type="javax.mail.Session"    
mail.smtp.host="localhost" mail.store.protocol="imap"
</Context>
web.xml

<resource-ref>
<res-ref-name>mail/session</res-ref-name>
<res-type>javax.mail.Session</res-type>
<res-auth>Container</res-auth>
</resource-ref>

Context ctx=new InitialContext();
if(ctx==null)
throw ex;
Session mailsession=(Session)ctx.lookup("java:comp/env/mail/session");
Store store=mailsession.