Transport (Java EE 5)

Java EE API


javax.mail Class Transport

java.lang.Object
  extended by javax.mail.Service
      extended by javax.mail.Transport

public abstract class Transport
extends Service

Extends: Service

模拟消息传输的抽象类。子类提供实际实现。

注意,Transport 扩展了 Service 类,该类提供了许多用于命名 transport、连接 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.

Version:
1.40, 07/05/17
Author:
John Mani, Max Spivak, Bill Shannon
See Also:
Service, ConnectionEvent, TransportEvent

Field Summary
 
Fields inherited from class javax.mail.Service
 
Constructor Summary
 
Method Summary
 void
protected  void
 void
static void
static void
abstract  void
 
Methods inherited from class javax.mail.Service
 
Methods inherited from class java.lang.Object
 

Constructor Detail

public Transport(Session session, URLName urlname)
构造方法。
session 此 Transport 的 Session 对象。
urlname 要用于此 Transport 的 URLName 对象
英文文档:

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

public static void send(Message msg) throws MessagingException
发送一条消息。使用对应于每个地址的消息传输,将消息发送到该消息中指定的所有接收方地址(Message 方法 getAllRecipients 返回的地址)。send 方法在发送消息之前对该消息调用 saveChanges 方法。

如果在消息提交期间 Transport 检测到任何无效接收方地址,则抛出 SendFailedException。客户端可通过检查该异常获得有关该失败的更多详细信息。该消息是否仍然成功发送到任何有效地址取决于 Transport 实现。有关更多详细信息,请参见 SendFailedException。还要注意的是,这里的成功并不意味着该消息被成功传送给最终接收方,因为失败可能发生在后面的传送阶段中。一旦 Transport 接受传送给接收方的消息,就应该通过另一个机制(如返回不可传送的消息)向用户报告后面发生的失败。

注意,send 是创建和管理其自身连接的静态方法。忽略且不使用所有与用来调用此方法的任何 Transport 实例关联的连接。应该只使用 Transport.send(msg); 的形式调用此方法,并且决不应该使用实例变量调用此方法。

msg 要发送的消息
ThrowsSendFailedException: 如果无法将消息发送给部分或全部接收方。
ThrowsMessagingException:
See also saveChanges, getAllRecipients, send(Message, Address[]), javax.mail.SendFailedException

英文文档:

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.

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

public static void send(Message msg, Address[] addresses) throws MessagingException
将消息发送到指定地址,同时忽略该消息本身中指定的任何接收方。send 方法在发送消息之前对该消息调用 saveChanges 方法。

msg 要发送的消息
addresses 消息要发送到的地址
ThrowsSendFailedException: 如果无法将消息发送给部分或全部接收方。
ThrowsMessagingException:
See also saveChanges, send(Message), javax.mail.SendFailedException

英文文档:

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.

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

abstract public void sendMessage(Message msg, Address[] addresses) throws MessagingException
将 Message 发送到指定地址列表。向此 Transport 上注册的所有 TransportListener 传送指示传送状态的相应 TransportEvent。此外,如果存在任何无效地址,则抛出 SendFailedException。该消息是否仍然成功发送到任何有效地址取决于 Transport 实现。

与静态 send 方法不同,sendMessage 方法 对消息调用 saveChanges 方法;调用者应该这样做。

msg 将被发送的 Message
addresses 此消息要发送到的地址的数组
ThrowsSendFailedException: 如果由于无效地址导致发送失败。
ThrowsMessagingException: 如果连接停用或未处于连接状态
See also javax.mail.event.TransportEvent

英文文档:

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

public void addTransportListener(TransportListener l)
添加 Transport 事件侦听器。

此处提供的默认实现将此侦听器添加到 TransportListener 的内部列表。

l Transport 事件的 Listener
See also javax.mail.event.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

public void removeTransportListener(TransportListener l)
移除 Transport 事件侦听器。

此处提供的默认实现将从 TransportListener 的内部列表中移除此侦听器。

l 侦听器
See also addTransportListener

英文文档:

removeTransportListener

public void removeTransportListener(TransportListener l)
Remove a listener for Transport events.

The default implementation provided here removes this listener from the internal list of TransportListeners.

Parameters:
l - the listener
See Also:
addTransportListener(javax.mail.event.TransportListener)

protected void notifyTransportListeners(int type, Address[] validSent, Address[] validUnsent, Address[] invalid, Message msg)
通知所有 TransportListener。Transport 实现应该使用此方法广播 TransportEvent。

提供的默认实现将该事件加入到内部事件队列。事件分发程序线程取消队列中事件的排队,并将其分发给注册的 TransportListener。注意,事件分发发生在不同的线程中,因此避免了可能出现的死锁问题。

英文文档:

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.



Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!