Package javax.mail
Class Service
- java.lang.Object
-
- javax.mail.Service
-
public abstract class Service extends java.lang.Object
An abstract messaging service (store or transport).- Version:
- 1.4
- Author:
- Chris Burdess
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addConnectionListener(ConnectionListener l)
Adds a listener for connection events on this service.void
close()
Closes this service, terminating any underlying connections.void
connect()
Connects to this service.void
connect(java.lang.String host, int port, java.lang.String user, java.lang.String password)
Connects to this service using the specified details.void
connect(java.lang.String user, java.lang.String password)
Connects to this service.void
connect(java.lang.String host, java.lang.String user, java.lang.String password)
Connects to this service using the specified details.URLName
getURLName()
Return a URLName representing this service.boolean
isConnected()
Indicates whether this service is currently connected.protected void
notifyConnectionListeners(int type)
Notify all connection listeners.protected boolean
protocolConnect(java.lang.String host, int port, java.lang.String user, java.lang.String password)
Provider implementation for a service.protected void
queueEvent(MailEvent event, java.util.Vector vector)
Adds the event and vector of listeners to be notified.void
removeConnectionListener(ConnectionListener l)
Removes a connection event listener.protected void
setConnected(boolean connected)
Sets the connection state of this service.protected void
setURLName(URLName url)
Set the URLName representing this service.java.lang.String
toString()
ReturnsgetURLName.toString
if this service has a URLName, otherwise returns the defaulttoString
.
-
-
-
Method Detail
-
connect
public void connect() throws MessagingException
Connects to this service. If additional information is required, the provider can determine them from session properties or via a callback to the UI.- Throws:
AuthenticationFailedException
- on authentication failureMessagingException
- for other failuresjava.lang.IllegalStateException
- if the service is already connected
-
connect
public void connect(java.lang.String user, java.lang.String password) throws MessagingException
Connects to this service. This method provides a simple authentication scheme requiring a username and password. The host is determined from the inital URLName.- Parameters:
user
- the usernamepassword
- the password- Throws:
AuthenticationFailedException
- on authentication failureMessagingException
- for other failuresjava.lang.IllegalStateException
- if the service is already connected- Since:
- JavaMail 1.4
-
connect
public void connect(java.lang.String host, java.lang.String user, java.lang.String password) throws MessagingException
Connects to this service using the specified details. This method provides a simple authentication scheme requiring a username and password.- Parameters:
host
- the host to connect touser
- the usernamepassword
- the password- Throws:
AuthenticationFailedException
- on authentication failureMessagingException
- for other failuresjava.lang.IllegalStateException
- if the service is already connected
-
connect
public void connect(java.lang.String host, int port, java.lang.String user, java.lang.String password) throws MessagingException
Connects to this service using the specified details. This method provides a simple authentication scheme requiring a username and password.- Parameters:
host
- the host to connect toport
- the port to use (-1 for the default port)user
- the usernamepassword
- the password- Throws:
AuthenticationFailedException
- on authentication failureMessagingException
- for other failuresjava.lang.IllegalStateException
- if the service is already connected
-
protocolConnect
protected boolean protocolConnect(java.lang.String host, int port, java.lang.String user, java.lang.String password) throws MessagingException
Provider implementation for a service.This method should return
false
if authentication fails, due to the username or password being unavailable or incorrect, or may throwAuthenticationFailedException
for further details.In the case of failures not related to authentication, such as an invalid configuration or network error, this method should throw an appropriate
MessagingException
.- Parameters:
host
- the name of the host to connect toport
- the port to use (-1 for the default port)user
- the usernamepassword
- the password- Returns:
- true on success, false if authentication failed
- Throws:
AuthenticationFailedException
- on authentication failureMessagingException
- for non-authentication failures
-
isConnected
public boolean isConnected()
Indicates whether this service is currently connected.
-
setConnected
protected void setConnected(boolean connected)
Sets the connection state of this service.
-
close
public void close() throws MessagingException
Closes this service, terminating any underlying connections.- Throws:
MessagingException
-
getURLName
public URLName getURLName()
Return a URLName representing this service. The password field will not be returned.
-
setURLName
protected void setURLName(URLName url)
Set the URLName representing this service. This method is called when the service has successfully connected.
-
addConnectionListener
public void addConnectionListener(ConnectionListener l)
Adds a listener for connection events on this service.
-
removeConnectionListener
public void removeConnectionListener(ConnectionListener l)
Removes a connection event listener.
-
notifyConnectionListeners
protected void notifyConnectionListeners(int type)
Notify all connection listeners.
-
toString
public java.lang.String toString()
ReturnsgetURLName.toString
if this service has a URLName, otherwise returns the defaulttoString
.- Overrides:
toString
in classjava.lang.Object
-
queueEvent
protected void queueEvent(MailEvent event, java.util.Vector vector)
Adds the event and vector of listeners to be notified.
-
-