public abstract class Transport extends Service
Note that Transport
extends the Service
class, which provides many common methods for naming transports,
connecting to transports, and listening to connection events.
Service
,
ConnectionEvent
,
TransportEvent
Constructor and Description |
---|
Transport(Session session,
URLName urlname)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addTransportListener(TransportListener l)
Add a listener for Transport events.
|
protected void |
notifyTransportListeners(int type,
Address[] validSent,
Address[] validUnsent,
Address[] invalid,
Message msg)
Notify all TransportListeners.
|
void |
removeTransportListener(TransportListener l)
Remove a listener for Transport events.
|
static void |
send(Message msg)
Send a message.
|
static void |
send(Message msg,
Address[] addresses)
Send the message to the specified addresses, ignoring any
recipients specified in the message itself.
|
static void |
send(Message msg,
Address[] addresses,
java.lang.String user,
java.lang.String password)
Send the message to the specified addresses, ignoring any
recipients specified in the message itself.
|
static void |
send(Message msg,
java.lang.String user,
java.lang.String password)
Send a message.
|
abstract void |
sendMessage(Message msg,
Address[] addresses)
Send the Message to the specified list of addresses.
|
addConnectionListener, close, connect, connect, connect, connect, finalize, getURLName, isConnected, notifyConnectionListeners, protocolConnect, queueEvent, removeConnectionListener, setConnected, setURLName, toString
public static void send(Message msg) throws MessagingException
Message
method getAllRecipients
),
using message transports appropriate to each address. The
send
method calls the saveChanges
method on the message before sending it. If any of the recipient addresses is detected to be invalid by the Transport during message submission, a SendFailedException is thrown. Clients can get more detail about the failure by examining the exception. Whether or not the message is still sent successfully to any valid addresses depends on the Transport implementation. See SendFailedException for more details. Note also that success does not imply that the message was delivered to the ultimate recipient, as failures may occur in later stages of delivery. Once a Transport accepts a message for delivery to a recipient, failures that occur later should be reported to the user via another mechanism, such as returning the undeliverable message.
In typical usage, a SendFailedException reflects an error detected by the server. The details of the SendFailedException will usually contain the error message from the server (such as an SMTP error message). An address may be detected as invalid for a variety of reasons - the address may not exist, the address may have invalid syntax, the address may have exceeded its quota, etc.
Note that send
is a static method that creates and
manages its own connection. Any connection associated with any
Transport instance used to invoke this method is ignored and not
used. This method should only be invoked using the form
Transport.send(msg);
, and should never be invoked
using an instance variable.
msg
- the message to sendSendFailedException
- if the message could not
be sent to some or any of the recipients.MessagingException
- for other failuresMessage.saveChanges()
,
Message.getAllRecipients()
,
send(Message, Address[])
,
SendFailedException
public static void send(Message msg, Address[] addresses) throws MessagingException
send
method calls the saveChanges
method on the message before sending it. msg
- the message to sendaddresses
- the addresses to which to send the messageSendFailedException
- if the message could not
be sent to some or any of the recipients.MessagingException
- for other failuresMessage.saveChanges()
,
send(Message)
,
SendFailedException
public static void send(Message msg, java.lang.String user, java.lang.String password) throws MessagingException
Message
method getAllRecipients
).
The send
method calls the saveChanges
method on the message before sending it. Use the specified user name and password to authenticate to the mail server.
msg
- the message to senduser
- the user namepassword
- this user's passwordSendFailedException
- if the message could not
be sent to some or any of the recipients.MessagingException
- for other failuresMessage.saveChanges()
,
send(Message)
,
SendFailedException
public static void send(Message msg, Address[] addresses, java.lang.String user, java.lang.String password) throws MessagingException
send
method calls the saveChanges
method on the message before sending it. Use the specified user name and password to authenticate to the mail server.
msg
- the message to sendaddresses
- the addresses to which to send the messageuser
- the user namepassword
- this user's passwordSendFailedException
- if the message could not
be sent to some or any of the recipients.MessagingException
- for other failuresMessage.saveChanges()
,
send(Message)
,
SendFailedException
public abstract void sendMessage(Message msg, Address[] addresses) throws MessagingException
Unlike the static send
method, the sendMessage
method does not call the saveChanges
method on
the message; the caller should do so.
msg
- The Message to be sentaddresses
- array of addresses to send this message toSendFailedException
- if the send failed because of
invalid addresses.MessagingException
- if the connection is dead or not in the
connected stateTransportEvent
public void addTransportListener(TransportListener l)
The default implementation provided here adds this listener to an internal list of TransportListeners.
l
- the Listener for Transport eventsTransportEvent
public void removeTransportListener(TransportListener l)
The default implementation provided here removes this listener from the internal list of TransportListeners.
l
- the listeneraddTransportListener(javax.mail.event.TransportListener)
protected void notifyTransportListeners(int type, Address[] validSent, Address[] validUnsent, Address[] invalid, Message msg)
The provided default implementation queues the event into an internal event queue. An event dispatcher thread dequeues events from the queue and dispatches them to the registered TransportListeners. Note that the event dispatching occurs in a separate thread, thus avoiding potential deadlock problems.
type
- the TransportEvent typevalidSent
- valid addresses to which message was sentvalidUnsent
- valid addresses to which message was not sentinvalid
- the invalid addressesmsg
- the message