javax.mail
Class Transport
public abstract class Transport
An abstract class that models a message transport.
Subclasses provide actual implementations.
Note that Transport extends the Service class, which provides many common
methods for naming transports, connecting to transports, and listening to
connection events.
addConnectionListener , close , connect , connect , connect , getURLName , isConnected , notifyConnectionListeners , protocolConnect , removeConnectionListener , setConnected , setURLName , toString |
Transport
public Transport(Session session,
URLName url)
Constructor.
session
- Session object for this Transport.url
- URLName object to be used for this Transport
addTransportListener
public void addTransportListener(TransportListener l)
Add a listener for Transport events.
notifyTransportListeners
protected void notifyTransportListeners(int type,
Address[] validSent,
Address[] validUnsent,
Address[] invalid,
Message msg)
Notify all TransportListeners. Transport implementations are expected to
use this method to broadcast TransportEvents.
removeTransportListener
public void removeTransportListener(TransportListener l)
Remove a listener for Transport events.
send
public static void send(Message msg)
throws MessagingException
Send a message.
The message will be sent to all recipient addresses specified in the
message(as returned from the 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 succesfully 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.
msg
- the message to send
send
public static void send(Message msg,
Address[] addresses)
throws MessagingException
Send the message to the specified addresses, ignoring any recipients
specified in the message itself. The send
method calls
the saveChanges
method on the message before sending it.
msg
- the message to sendaddresses
- the addresses to which to send the message
sendMessage
public void sendMessage(Message msg,
Address[] addresses)
throws MessagingException
Send the Message to the specified list of addresses.
An appropriate TransportEvent indicating the delivery status is
delivered to any TransportListener registered on this Transport.
Also, if any of the addresses is invalid, a SendFailedException is
thrown. Note however, that the message is sent to the valid addresses.
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
- List of addresses to send this message to
MessagingException
- if the connection is dead
or not in the connected state