JavaMail - Mail session from JNDI(coded)
privatestatic Session getSession(){
Session session =null;
try{
Context ctx =new InitialContext();
Context envCtx = (Context) ctx.lookup("java:comp/env");
session = (Session) envCtx.lookup("mail/Session");
}catch (Exception e){
logger.error(e);
}
return session;
}
My question is basically that we have bound the mail/Session to the context and this code is picking it up from the server.xml file of tomcat.If i have to bind that in java code instead of server.xml(Server is not running),how to do that.Can anyone provide me with an example.

