javax.mail

Class Transport


  • public abstract class Transport
    extends Service
    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.

    Author:
    John Mani, Max Spivak, Bill Shannon
    See Also:
    Service, ConnectionEvent, TransportEvent
    • Constructor Detail

      • Transport

        public Transport(Session session,
                         URLName urlname)
        Constructor.
        Parameters:
        session - Session object for this Transport.
        urlname - URLName object to be used for this Transport
    • Method Detail

      • 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 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.

        Parameters:
        msg - the message to send
        Throws:
        SendFailedException - if the message could not be sent to some or any of the recipients.
        MessagingException
        See Also:
        Message.saveChanges(), Message.getAllRecipients(), send(Message, Address[]), SendFailedException
      • send

        public static void send(Message msg,
                                String user,
                                String password)
                         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). 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.

        Parameters:
        msg - the message to send
        user - the user name
        password - this user's password
        Throws:
        SendFailedException - if the message could not be sent to some or any of the recipients.
        MessagingException
        Since:
        JavaMail 1.5
        See Also:
        Message.saveChanges(), send(Message), SendFailedException
      • send

        public static void send(Message msg,
                                Address[] addresses,
                                String user,
                                String password)
                         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.

        Use the specified user name and password to authenticate to the mail server.

        Parameters:
        msg - the message to send
        addresses - the addresses to which to send the message
        user - the user name
        password - this user's password
        Throws:
        SendFailedException - if the message could not be sent to some or any of the recipients.
        MessagingException
        Since:
        JavaMail 1.5
        See Also:
        Message.saveChanges(), send(Message), SendFailedException
      • sendMessage

        public abstract 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. Whether or not the message is still sent succesfully to any valid addresses depends on the Transport implementation.

        Unlike the static send method, the sendMessage method does not call the saveChanges method on the message; the caller should do so.

        Parameters:
        msg - The Message to be sent
        addresses - array of addresses to send this message to
        Throws:
        SendFailedException - if the send failed because of invalid addresses.
        MessagingException - if the connection is dead or not in the connected state
        See Also:
        TransportEvent
      • addTransportListener

        public void addTransportListener(TransportListener l)
        Add a listener for Transport events.

        The default implementation provided here adds this listener to an internal list of TransportListeners.

        Parameters:
        l - the Listener for Transport events
        See Also:
        TransportEvent
      • 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.

        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.

Traduction non disponible

Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.

Version en cache

21/08/2025 14:26:48 Cette version de la page est en cache (à la date du 21/08/2025 14:26:48) afin d'accélérer le traitement.
Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la version plus récente de la page.

Document créé le 14/04/2008, dernière modification le 18/08/2025
Source du document imprimé : https://www.gaudry.be/java-api-javaee-rf-javax/mail/Transport.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.

Références

  1. Consulter le document html Langue du document :fr Manuel PHP : https://docs.oracle.com, Transport (Java(TM) EE 7 Specification APIs)

Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.