Skip to content

Instantly share code, notes, and snippets.

@MiloCasagrande
Created April 27, 2012 13:48
Show Gist options
  • Select an option

  • Save MiloCasagrande/2509400 to your computer and use it in GitHub Desktop.

Select an option

Save MiloCasagrande/2509400 to your computer and use it in GitHub Desktop.
Retrieve JavaMail Session
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