java.lang.Object | +--javax.mail.Session
The Session class represents a mail session and is not subclassed. It collects together properties and defaults used by the mail API's. A single default session can be shared by multiple applications on the desktop. Unshared sessions can also be created.
getDebug() Get the debug setting for this Session. | |
getDefaultInstance(java.util.Properties props,Authenticator authenticator) Get the default Session object. | |
getFolder(URLName url) Get a closed Folder object for the given URLName. | |
getInstance(java.util.Properties props,Authenticator authenticator) Get a new Session object. | |
getPasswordAuthentication(URLName url) Return any saved PasswordAuthentication for this (store or transport) URLName. | |
getProperties() Returns the Properties object associated with this Session | |
getProperty(java.lang.String name) Returns the value of the specified property. | |
getProvider(java.lang.String protocol) Returns the default Provider for the protocol specified. | |
getProviders() This method returns an array of all the implementations installed via the javamail.[default.]providers files that can be loaded using the ClassLoader available to this application. | |
getStore() Get a Store object that implements this user's desired Store protcol. | |
getStore(Provider provider) Get an instance of the store specified by Provider. | |
getStore(java.lang.String protocol) Get a Store object that implements the specified protocol. | |
getStore(URLName url) Get a Store object for the given URLName. | |
getTransport() Get a Transport object that implements this user's desired Transport protcol. | |
getTransport(Address address) Get a Transport object that can transport a Message to the specified address type. | |
getTransport(Provider provider) Get an instance of the transport specified in the Provider. | |
getTransport(java.lang.String protocol) Get a Transport object that implements the specified protocol. | |
getTransport(URLName url) Get a Transport object for the given URLName. | |
requestPasswordAuthentication(java.net.InetAddress addr, int port, java.lang.String protocol, java.lang.String prompt, java.lang.String defaultUserName) Call back to the application to get the needed user name and password. | |
setDebug(boolean debug) Set the debug setting for this Session. | |
setPasswordAuthentication(URLName url,PasswordAuthentication pw) Save a PasswordAuthentication for this (store or transport) URLName. | |
setProvider(Provider provider) Set the passed Provider to be the default implementation for the protocol in Provider.protocol overriding any previous values. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
public staticSessiongetInstance(java.util.Properties props,Authenticator authenticator)
props
- Properties object that hold relevant properties.authenticator
- Authenticator object used to call back tothe application when a user name and password isneeded.Authenticator
public staticSessiongetDefaultInstance(java.util.Properties props,Authenticator authenticator)
Since the default session is potentially available to all code executing in the same Java virtual machine, and the session can contain security sensitive information such as user names and passwords, access to the default session is restricted. The Authenticator object, which must be created by the caller, is used indirectly to check access permission. The Authenticator object passed in when the session is created is compared with the Authenticator object passed in to subsequent requests to get the default session. If both objects are the same, or are from the same ClassLoader, the request is allowed. Otherwise, it is denied.
Note that if the Authenticator object used to create the session is null, anyone can get the default session by passing in null.
In JDK 1.2, additional security Permission objects may be used to control access to the default session.
props
- Properties object. Used only if a new Sessionobject is created.authenticator
- Authenticator object. Used only if anew Session object is created. Otherwise, it must match the Authenticator used to createthe Session.public voidsetDebug(boolean debug)
Since debug can be turned on only after the Session has been created, to turn on debugging in the Session constructor, set the propertymail.debug
to true. Subsequent calls to get/setDebug() have no affect on and override themail.debug
property.
debug
- Debug settingpublic booleangetDebug()
Since debug can be turned on only after the Session has been created, to turn on debugging in the Session constructor, set the propertymail.debug
to true. Subsequent calls to get/setDebug() have no affect on and override themail.debug
property.
publicProvider[]getProviders()
publicProvidergetProvider(java.lang.String protocol) throwsNoSuchProviderException
protocol
- Configured protocol (i.e. smtp, imap, etc)NoSuchProviderException
- If a provider for the givenprotocol is not found.public voidsetProvider(Provider provider) throwsNoSuchProviderException
provider
- Currently configured Provider which will be set as the default for the protocolNoSuchProviderException
- If the provider passed inis invalid.publicStoregetStore() throwsNoSuchProviderException
NoSuchProviderException
- If a provider for the givenprotocol is not found.publicStoregetStore(java.lang.String protocol) throwsNoSuchProviderException
protocol
- NoSuchProviderException
- If a provider for the givenprotocol is not found.publicStoregetStore(URLName url) throwsNoSuchProviderException
url
- URLName that represents the desired StoreNoSuchProviderException
- If a provider for the givenURLName is not found.getFolder(URLName)
,URLName
publicStoregetStore(Provider provider) throwsNoSuchProviderException
provider
- Store Provider that will be instantiatedNoSuchProviderException
- If a provider for the givenProvider is not found.publicFoldergetFolder(URLName url) throwsMessagingException
The "scheme" part of the URL string (Refer RFC 1738) is used to locate the Store protocol. The rest of the URL string (ie the "schemepart", as per RFC 1738) is used by that Store in a protocol dependent manner to locate and instantiate the appropriate Folder object.
Note that RFC 1738 also specifies the syntax for the "schemepart" for IP-based protocols (IMAP4, POP3 etc). So providers of IP-based mail Stores should implement that syntax for referring to Folders.
url
- URLName that represents the desired folderNoSuchProviderException
- If a provider for the givenURLName is not found.MessagingException
- if the Folder could not be located or created.getStore(URLName)
,URLName
publicTransportgetTransport() throwsNoSuchProviderException
NoSuchProviderException
- If the provider is not found.publicTransportgetTransport(java.lang.String protocol) throwsNoSuchProviderException
NoSuchProviderException
- If provider for the givenprotocol is not found.publicTransportgetTransport(URLName url) throwsNoSuchProviderException
url
- URLName that represents the desired TransportNoSuchProviderException
- If a provider for the givenURLName is not found.URLName
publicTransportgetTransport(Provider provider) throwsNoSuchProviderException
provider
- Transport Provider that will be instantiatedNoSuchProviderException
- If provider for the givenprovider is not found.publicTransportgetTransport(Address address) throwsNoSuchProviderException
address
- NoSuchProviderException
- If provider for the Address type is not foundAddress
public voidsetPasswordAuthentication(URLName url,PasswordAuthentication pw)
This is normally used only by the store or transport implementations to allow authentication information to be shared among multiple uses of a session.
publicPasswordAuthenticationgetPasswordAuthentication(URLName url)
publicPasswordAuthenticationrequestPasswordAuthentication(java.net.InetAddress addr, int port, java.lang.String protocol, java.lang.String prompt, java.lang.String defaultUserName)
Connecting to <protocol> mail service on host <addr>, port <port>. <prompt> User Name: <defaultUserName> Password:
addr
- InetAddress of the host. may be null.protocol
- protocol scheme (e.g. imap, pop3, etc.)prompt
- any additional String to show as part of the prompt; may be null.defaultUserName
- the default username. may be null.public java.util.PropertiesgetProperties()
public java.lang.StringgetProperty(java.lang.String name)