Created
April 27, 2012 13:48
-
-
Save MiloCasagrande/2509400 to your computer and use it in GitHub Desktop.
Retrieve JavaMail Session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public Session getSession() { | |
| Session session = null; | |
| try { | |
| final Context rootContext = new InitialContext(); | |
| // This is the default Java context to lookup | |
| final Context envContext = (Context) rootContext.lookup("java:comp/env"); | |
| // This is the JNDI name of the JavaMail session as defined in Glassfish | |
| session = (Session) envContext.lookup("mail/newsession"); | |
| } catch (final NamingException ex) { | |
| ex.printStackTrace(); | |
| } | |
| return session; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment