Session getDefaultInstance Example
Session class getDefaultInstance example. This example shows you how to use getDefaultInstance method.
Session class getDefaultInstance example. public static Session getDefaultInstance(Properties props, Authenticator authenticator) Get the default Session object. If a default has not yet been setup, a new Session object is created and installed as the default.
Here is the code
/*
* @ # GetDefaultInstance.java
* A class repersenting use to GetDefaultInstance method
* of Session class in javax.mail package
* version 05 July 2008
* author Rose India
*/
package session;
import java.util.*;
import javax.mail.*;
public class GetDefaultInstance1 {
public static void main(String args[]) throws Exception {
Properties properties = System.getProperties();
Authenticator authenticator = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("username", "password");
}
};
Session session = Session.getDefaultInstance(properties, authenticator);
System.out.println("Debug setting for this Session. " + session.getDebug());
}
} |
Output
| Debug setting for this Session. false |
|