Session (Java EE 5)

Java EE API


javax.mail Class Session

java.lang.Object
  extended by javax.mail.Session

public final class Session
extends Object


Session 类表示邮件会话,无法为 Session 类创建子类。它将邮件 API 使用的属性和默认值收集在一起。桌面上的多个应用程序可共享一个默认会话。也可以创建非共享的会话。

Session 类提供对实现 StoreTransport 和相关类的协议提供者的访问。协议提供者是使用以下文件配置的:

  • javamail.providersjavamail.default.providers
  • javamail.address.mapjavamail.default.address.map

按以下顺序使用三个方法搜索每个 javamail.X 资源文件:

  1. java.home/lib/javamail.X
  2. META-INF/javamail.X
  3. META-INF/javamail.default.X

第一种方法允许用户包含自己的资源文件版本,实现方式是将资源文件放在 java.home 属性指向的 lib 目录中。第二种方法允许使用 JavaMail API 的应用程序在其应用程序或 jar 文件的 META-INF 目录中包含自己的资源文件。javamail.default.X 默认文件是 JavaMail mail.jar 文件的一部分。

文件位置取决于 ClassLoader 方法 getResource 的实现方式。通常,getResource 方法会搜索整个 CLASSPATH,直到找到请求的文件,然后停止。JDK 1.1 对将要在 CLASSPATH 中找到的每个名称的文件数有所限制,该文件数被限制为 1。但是,这只会影响上述的方法二;方法一是从特定位置加载的(如果 SecurityManager 允许);而方法三使用不同的名称以确保默认资源文件总是能成功加载。J2SE 1.2 和以后的版本都未将给定名称的文件数限制为 1。

资源文件中条目的排序非常重要。如果存在多个条目,则第一个条目优先于后面的条目。例如,找到的第一个 IMAP 提供者将会被设置为默认 IMAP 实现,直到被应用程序显式更改为止。用户或系统提供的资源文件扩充(它们不会重写)JavaMail API 包含的默认文件。这意味着所有已加载文件中的所有条目都将是可用的。

javamail.providersjavamail.default.providers

这些资源文件指定系统上可用的 store 和 transport,同时允许应用程序“发现”哪些 store 和 transport 实现是可用的。协议实现以每行一个的形式列出。该文件格式定义了四个描述协议实现的属性。每个属性都是一个用 "=" 分隔的名称-值对,其中名称为小写。每个名称-值对都是由分号 (";") 分隔的。定义了以下名称。

提供者文件中的属性名称
名称描述

以下是 META-INF/javamail.default.providers 文件内容的示例:

protocol=imap; type=store; class=com.sun.mail.imap.IMAPStore; vendor=Sun Microsystems, Inc.;
protocol=smtp; type=transport; class=com.sun.mail.smtp.SMTPTransport; vendor=Sun Microsystems, Inc.;
 

javamail.address.mapjavamail.default.address.map

这些资源文件将传输地址类型映射到传输协议。javax.mail.AddressgetType 方法返回地址类型。javamail.address.map 文件将传输类型映射到协议。该文件格式是一系列名称-值对。每个键名都应该与系统上当前安装的地址类型相对应;还应该有条目用于存在的每个 javax.mail.Address 实现(如果要使用该实现的话)。例如,javax.mail.internet.InternetAddress 方法 getType 返回 "rfc822"。每个引用的协议都应该安装在系统上。对于下面的 news 例子,客户端应该安装支持 nntp 协议的 Transport 提供者。

以下是 javamail.address.map 文件通常的内容:

rfc822=smtp
news=nntp
 
英文文档:

The Session class represents a mail session and is not subclassed. It collects together properties and defaults used by the mail API's. A single default session can be shared by multiple applications on the desktop. Unshared sessions can also be created.

The Session class provides access to the protocol providers that implement the Store, Transport, and related classes. The protocol providers are configured using the following files:

  • javamail.providers and javamail.default.providers
  • javamail.address.map and javamail.default.address.map

Each javamail.X resource file is searched for using three methods in the following order:

  1. java.home/lib/javamail.X
  2. META-INF/javamail.X
  3. META-INF/javamail.default.X

The first method allows the user to include their own version of the resource file by placing it in the lib directory where the java.home property points. The second method allows an application that uses the JavaMail APIs to include their own resource files in their application's or jar file's META-INF directory. The javamail.default.X default files are part of the JavaMail mail.jar file.

File location depends upon how the ClassLoader method getResource is implemented. Usually, the getResource method searches through CLASSPATH until it finds the requested file and then stops. JDK 1.1 has a limitation that the number of files of each name that will be found in the CLASSPATH is limited to one. However, this only affects method two, above; method one is loaded from a specific location (if allowed by the SecurityManager) and method three uses a different name to ensure that the default resource file is always loaded successfully. J2SE 1.2 and later are not limited to one file of a given name.

The ordering of entries in the resource files matters. If multiple entries exist, the first entries take precedence over the later entries. For example, the first IMAP provider found will be set as the default IMAP implementation until explicitly changed by the application. The user- or system-supplied resource files augment, they do not override, the default files included with the JavaMail APIs. This means that all entries in all files loaded will be available.

javamail.providers and javamail.default.providers

These resource files specify the stores and transports that are available on the system, allowing an application to "discover" what store and transport implementations are available. The protocol implementations are listed one per line. The file format defines four attributes that describe a protocol implementation. Each attribute is an "="-separated name-value pair with the name in lowercase. Each name-value pair is semi-colon (";") separated. The following names are defined.

Attribute Names in Providers Files
NameDescription

Here's an example of META-INF/javamail.default.providers file contents:

 protocol=imap; type=store; class=com.sun.mail.imap.IMAPStore; vendor=Sun Microsystems, Inc.;
 protocol=smtp; type=transport; class=com.sun.mail.smtp.SMTPTransport; vendor=Sun Microsystems, Inc.;
 

javamail.address.map and javamail.default.address.map

These resource files map transport address types to the transport protocol. The getType method of javax.mail.Address returns the address type. The javamail.address.map file maps the transport type to the protocol. The file format is a series of name-value pairs. Each key name should correspond to an address type that is currently installed on the system; there should also be an entry for each javax.mail.Address implementation that is present if it is to be used. For example, the javax.mail.internet.InternetAddress method getType returns "rfc822". Each referenced protocol should be installed on the system. For the case of news, below, the client should install a Transport provider supporting the nntp protocol.

Here are the typical contents of a javamail.address.map file:

 rfc822=smtp
 news=nntp
 

Version:
1.76, 07/05/04
Author:
John Mani, Bill Shannon, Max Spivak

Method Summary
 void
 boolean
 PrintStream
static Session
static Session
 Folder
static Session
static Session
 PasswordAuthentication
 Properties
 String
 Provider
 Provider[]
 Store
 Store
 Store
 Store
 Transport
 Transport
 Transport
 Transport
 Transport
 PasswordAuthentication
 void
 void
 void
 void
 void
 
Methods inherited from class java.lang.Object
 

Method Detail

public static Session getInstance(java.util.Properties props, Authenticator authenticator)
获取新 Session 对象。
props 保存相关属性的 Properties 对象。
客户端应该为 JavaMail 规范附录 A 中列出的属性(尤其是 mail.store.protocol、mail.transport.protocol、mail.host、mail.user 和 mail.from)提供值,因为默认值不可能适用于所有情况。
authenticator 需要用户名和密码时用来回调应用程序的 Authenticator 对象。
return 新 Session 对象
See also javax.mail.Authenticator
英文文档:

getInstance

public static Session getInstance(Properties props,
                                  Authenticator authenticator)
Get a new Session object.

Parameters:
props - Properties object that hold relevant properties.
It is expected that the client supplies values for the properties listed in Appendix A of the JavaMail spec (particularly mail.store.protocol, mail.transport.protocol, mail.host, mail.user, and mail.from) as the defaults are unlikely to work in all cases.
authenticator - Authenticator object used to call back to the application when a user name and password is needed.
Returns:
a new Session object
See Also:
Authenticator

public static Session getInstance(java.util.Properties props)
获取新 Session 对象。
props 保存相关属性的 Properties 对象。
客户端应该为 JavaMail 规范附录 A 中列出的属性(尤其是 mail.store.protocol、mail.transport.protocol、mail.host、mail.user 和 mail.from)提供值,因为默认值不可能适用于所有情况。
return 新 Session 对象
since
JavaMail 1.2
英文文档:

getInstance

public static Session getInstance(Properties props)
Get a new Session object.

Parameters:
props - Properties object that hold relevant properties.
It is expected that the client supplies values for the properties listed in Appendix A of the JavaMail spec (particularly mail.store.protocol, mail.transport.protocol, mail.host, mail.user, and mail.from) as the defaults are unlikely to work in all cases.
Returns:
a new Session object
Since:
JavaMail 1.2

public static Session getDefaultInstance(java.util.Properties props, Authenticator authenticator)
获取默认 Session 对象。如果还没有设置默认对象,则将创建一个新 Session 对象,并将其作为默认对象安装。

由于默认会话可能对同一 Java 虚拟机上正在执行的所有代码都可用,并且该会话可能包含安全性敏感信息,比如用户名和密码,因此对默认会话的访问是受限制的。Authenticator 对象(必须由调用者创建)间接用于检查访问权限。将创建会话时传入的 Authenticator 对象与给后续请求传入的 Authenticator 对象进行比较以获得默认会话。如果两个对象是相同的,或者它们来自相同的 ClassLoader,则允许请求。否则,拒绝它。

注意,如果用于创建会话的 Authenticator 对象为 null,则任何人都可以通过传入 null 获得默认会话。

还要注意,创建新 Session 对象时,Properties 对象仅在第一次调用此方法时使用。后续调用返回第一次调用创建的 Session 对象,并忽略传递的 Properties 对象。每次调用 getInstance 方法时,都可以使用该方法获取一个新 Session 对象。

在 JDK 1.2 中,可能会使用其他安全性 Permission 对象控制对默认会话的访问。

props Properties 对象。仅在创建新 Session 对象时使用。
客户端应该为 JavaMail 规范附录 A 中列出的属性(尤其是 mail.store.protocol、mail.transport.protocol、mail.host、mail.user 和 mail.from)提供值,因为默认值不可能适用于所有情况。
authenticator Authenticator 对象。仅在创建新 Session 对象时使用。否则,它必须与用于创建 Session 的 Authenticator 匹配。
return 默认 Session 对象

英文文档:

getDefaultInstance

public static Session getDefaultInstance(Properties props,
                                         Authenticator authenticator)
Get the default Session object. If a default has not yet been setup, a new Session object is created and installed as the default.

Since the default session is potentially available to all code executing in the same Java virtual machine, and the session can contain security sensitive information such as user names and passwords, access to the default session is restricted. The Authenticator object, which must be created by the caller, is used indirectly to check access permission. The Authenticator object passed in when the session is created is compared with the Authenticator object passed in to subsequent requests to get the default session. If both objects are the same, or are from the same ClassLoader, the request is allowed. Otherwise, it is denied.

Note that if the Authenticator object used to create the session is null, anyone can get the default session by passing in null.

Note also that the Properties object is used only the first time this method is called, when a new Session object is created. Subsequent calls return the Session object that was created by the first call, and ignore the passed Properties object. Use the getInstance method to get a new Session object every time the method is called.

In JDK 1.2, additional security Permission objects may be used to control access to the default session.

Parameters:
props - Properties object. Used only if a new Session object is created.
It is expected that the client supplies values for the properties listed in Appendix A of the JavaMail spec (particularly mail.store.protocol, mail.transport.protocol, mail.host, mail.user, and mail.from) as the defaults are unlikely to work in all cases.
authenticator - Authenticator object. Used only if a new Session object is created. Otherwise, it must match the Authenticator used to create the Session.
Returns:
the default Session object

public static Session getDefaultInstance(java.util.Properties props)
获取默认 Session 对象。如果没有设置默认对象,则将创建一个新 Session 对象,并将其作为默认对象安装。

注意,未使用 Authenticator 创建的默认会话对同一 Java 虚拟机上正在执行的所有代码都可用,并且该会话可能包含安全性敏感信息,比如用户名和密码。

props Properties 对象。仅在创建新 Session 对象时使用。
客户端应该为 JavaMail 规范附录 A 中列出的属性(尤其是 mail.store.protocol、mail.transport.protocol、mail.host、mail.user 和 mail.from)提供值,因为默认值不可能适用于所有情况。
return 默认 Session 对象
since
JavaMail 1.2

英文文档:

getDefaultInstance

public static Session getDefaultInstance(Properties props)
Get the default Session object. If a default has not yet been setup, a new Session object is created and installed as the default.

Note that a default session created with no Authenticator is available to all code executing in the same Java virtual machine, and the session can contain security sensitive information such as user names and passwords.

Parameters:
props - Properties object. Used only if a new Session object is created.
It is expected that the client supplies values for the properties listed in Appendix A of the JavaMail spec (particularly mail.store.protocol, mail.transport.protocol, mail.host, mail.user, and mail.from) as the defaults are unlikely to work in all cases.
Returns:
the default Session object
Since:
JavaMail 1.2

public void setDebug(boolean debug)
设置此 Session 的调试设置。

由于调试设置仅在已创建 Session 后开启,因此要开启 Session 构造方法中的调试,需要将传入构造方法的 Properties 对象中的属性 mail.debug 设置为 true。mail.debug 属性的值用于初始化每个 Session 的调试标志。对 setDebug 方法的后续调用可操作每个 Session 的调试标志,并且对 mail.debug 属性没有任何影响。

debug 调试设置

英文文档:

setDebug

public void setDebug(boolean debug)
Set the debug setting for this Session.

Since the debug setting can be turned on only after the Session has been created, to turn on debugging in the Session constructor, set the property mail.debug in the Properties object passed in to the constructor to true. The value of the mail.debug property is used to initialize the per-Session debugging flag. Subsequent calls to the setDebug method manipulate the per-Session debugging flag and have no affect on the mail.debug property.

Parameters:
debug - Debug setting

public boolean getDebug()
获取此 Session 的调试设置。
return 当前调试设置
英文文档:

getDebug

public boolean getDebug()
Get the debug setting for this Session.

Returns:
current debug setting

public void setDebugOut(java.io.PrintStream out)
设置用于此会话调试输出的流。如果 out 为 null,则将使用 System.out。注意,创建会话之前发生的调试输出将总是发送到 System.out,这是设置 mail.debug 系统属性的结果。
out 用于调试输出的 PrintStream
since
JavaMail 1.3
英文文档:

setDebugOut

public void setDebugOut(PrintStream out)
Set the stream to be used for debugging output for this session. If out is null, System.out will be used. Note that debugging output that occurs before any session is created, as a result of setting the mail.debug system property, will always be sent to System.out.

Parameters:
out - the PrintStream to use for debugging output
Since:
JavaMail 1.3

public java.io.PrintStream getDebugOut()
返回用于调试输出的流。如果没有设置流,则返回 System.out
return 用于调试输出的 PrintStream
since
JavaMail 1.3
英文文档:

getDebugOut

public PrintStream getDebugOut()
Returns the stream to be used for debugging output. If no stream has been set, System.out is returned.

Returns:
the PrintStream to use for debugging output
Since:
JavaMail 1.3

public Provider[] getProviders()
此方法返回通过 javamail.[default.]providers 文件安装的所有实现的数组,可以使用此应用程序可用的 ClassLoader 加载这些文件。
return 已配置的提供者的数组
英文文档:

getProviders

public Provider[] getProviders()
This method returns an array of all the implementations installed via the javamail.[default.]providers files that can be loaded using the ClassLoader available to this application.

Returns:
Array of configured providers

public Provider getProvider(String protocol) throws NoSuchProviderException
返回指定协议的默认 Provider。首先检查 mail.<protocol>.class 属性,如果该属性存在,则返回与此实现关联的 Provider。如果该属性不存在,则返回配置文件中出现的第一个 Provider。如果未找到该协议的实现,则抛出 NoSuchProviderException。
protocol 已配置的协议(即 smtp、imap,等等)
return 当前已为指定协议配置的 Provider
ThrowsNoSuchProviderException: 如果未找到给定协议的提供者。
英文文档:

getProvider

public Provider getProvider(String protocol)
                     throws NoSuchProviderException
Returns the default Provider for the protocol specified. Checks mail.<protocol>.class property first and if it exists, returns the Provider associated with this implementation. If it doesn't exist, returns the Provider that appeared first in the configuration files. If an implementation for the protocol isn't found, throws NoSuchProviderException

Parameters:
protocol - Configured protocol (i.e. smtp, imap, etc)
Returns:
Currently configured Provider for the specified protocol
Throws:
NoSuchProviderException - If a provider for the given protocol is not found.

public void setProvider(Provider provider) throws NoSuchProviderException
将传递的 Provider 设置为 Provider.protocol 中协议的默认实现,同时重写所有以前的值。
provider 当前配置的 Provider,它将被设置为协议的默认实现
ThrowsNoSuchProviderException: 如果传入的提供者无效。
英文文档:

setProvider

public void setProvider(Provider provider)
                 throws NoSuchProviderException
Set the passed Provider to be the default implementation for the protocol in Provider.protocol overriding any previous values.

Parameters:
provider - Currently configured Provider which will be set as the default for the protocol
Throws:
NoSuchProviderException - If the provider passed in is invalid.

public Store getStore() throws NoSuchProviderException
获取实现此用户所需的 Store 协议的 Store 对象。mail.store.protocol 属性指定所需协议。如果没有获得适当的 Store 对象,则抛出 NoSuchProviderException。
return Store 对象
ThrowsNoSuchProviderException: 如果未找到给定协议的提供者。
英文文档:

getStore

public Store getStore()
               throws NoSuchProviderException
Get a Store object that implements this user's desired Store protocol. The mail.store.protocol property specifies the desired protocol. If an appropriate Store object is not obtained, NoSuchProviderException is thrown

Returns:
a Store object
Throws:
NoSuchProviderException - If a provider for the given protocol is not found.

public Store getStore(String protocol) throws NoSuchProviderException
获取实现指定协议的 Store 对象。如果无法获得适当的 Store 对象,则抛出 NoSuchProviderException。
protocol
return Store 对象
ThrowsNoSuchProviderException: 如果未找到给定协议的提供者。
英文文档:

getStore

public Store getStore(String protocol)
               throws NoSuchProviderException
Get a Store object that implements the specified protocol. If an appropriate Store object cannot be obtained, NoSuchProviderException is thrown.

Parameters:
protocol -
Returns:
a Store object
Throws:
NoSuchProviderException - If a provider for the given protocol is not found.

public Store getStore(URLName url) throws NoSuchProviderException
获取给定 URLName 的 Store 对象。如果无法获得请求的 Store 对象,则抛出 NoSuchProviderException。 使用 URL 字符串的 "scheme" 部分(请参考 RFC 1738)定位 Store 协议。

url 表示所需 Store 的 URLName
return 关闭的 Store 对象
ThrowsNoSuchProviderException: 如果未找到给定 URLName 的提供者。
See also getFolder(URLName), javax.mail.URLName

英文文档:

getStore

public Store getStore(URLName url)
               throws NoSuchProviderException
Get a Store object for the given URLName. If the requested Store object cannot be obtained, NoSuchProviderException is thrown. The "scheme" part of the URL string (Refer RFC 1738) is used to locate the Store protocol.

Parameters:
url - URLName that represents the desired Store
Returns:
a closed Store object
Throws:
NoSuchProviderException - If a provider for the given URLName is not found.
See Also:
getFolder(URLName), URLName

public Store getStore(Provider provider) throws NoSuchProviderException
获取 Provider 指定的 store 的实例。实例化该 store 并将其返回。
provider 将被实例化的 Store Provider
return 实例化的 Store
ThrowsNoSuchProviderException: 如果未找到给定 Provider 的提供者。
英文文档:

getStore

public Store getStore(Provider provider)
               throws NoSuchProviderException
Get an instance of the store specified by Provider. Instantiates the store and returns it.

Parameters:
provider - Store Provider that will be instantiated
Returns:
Instantiated Store
Throws:
NoSuchProviderException - If a provider for the given Provider is not found.

public Folder getFolder(URLName url) throws MessagingException
获取给定 URLName 的关闭的 Folder 对象。如果无法获得请求的 Folder 对象,则返回 null。

使用 URL 字符串的 "scheme" 部分(请参考 RFC 1738)定位 Store 协议。该 Store 使用 URL 字符串的剩余部分(根据 RFC 1738,这部分是 "schemepart"),以与协议相关的方式定位和实例化相应的 Folder 对象。

注意,RFC 1738 还指定了基于 IP 的协议(IMAP4、POP3,等等)的 "schemepart" 的语法。基于 IP 的邮件 Store 的 Provider 应该实现该语法来引用 Folder。

url 表示所需文件夹的 URLName
return
Folder
ThrowsNoSuchProviderException: 如果未找到给定 URLName 的提供者。
ThrowsMessagingException: 如果无法定位或创建 Folder。
See also getStore(URLName), javax.mail.URLName

英文文档:

getFolder

public Folder getFolder(URLName url)
                 throws MessagingException
Get a closed Folder object for the given URLName. If the requested Folder object cannot be obtained, null is returned.

The "scheme" part of the URL string (Refer RFC 1738) is used to locate the Store protocol. The rest of the URL string (that is, the "schemepart", as per RFC 1738) is used by that Store in a protocol dependent manner to locate and instantiate the appropriate Folder object.

Note that RFC 1738 also specifies the syntax for the "schemepart" for IP-based protocols (IMAP4, POP3, etc.). Providers of IP-based mail Stores should implement that syntax for referring to Folders.

Parameters:
url - URLName that represents the desired folder
Returns:
Folder
Throws:
NoSuchProviderException - If a provider for the given URLName is not found.
MessagingException - if the Folder could not be located or created.
See Also:
getStore(URLName), URLName

public Transport getTransport() throws NoSuchProviderException
获取实现此用户所需的 Transport 协议的 Transport 对象。mail.transport.protocol 属性指定所需协议。如果无法获得适当的 Transport 对象,则抛出 MessagingException。
return Transport 对象
ThrowsNoSuchProviderException: 如果未找到提供者。
英文文档:

getTransport

public Transport getTransport()
                       throws NoSuchProviderException
Get a Transport object that implements this user's desired Transport protcol. The mail.transport.protocol property specifies the desired protocol. If an appropriate Transport object cannot be obtained, MessagingException is thrown.

Returns:
a Transport object
Throws:
NoSuchProviderException - If the provider is not found.

public Transport getTransport(String protocol) throws NoSuchProviderException
获取实现指定协议的 Transport 对象。如果无法获得适当的 Transport 对象,则返回 null。
return Transport 对象
ThrowsNoSuchProviderException: 如果未找到给定协议的提供者。
英文文档:

getTransport

public Transport getTransport(String protocol)
                       throws NoSuchProviderException
Get a Transport object that implements the specified protocol. If an appropriate Transport object cannot be obtained, null is returned.

Returns:
a Transport object
Throws:
NoSuchProviderException - If provider for the given protocol is not found.

public Transport getTransport(URLName url) throws NoSuchProviderException
获取给定 URLName 的 Transport 对象。如果无法获得请求的 Transport 对象,则抛出 NoSuchProviderException。 使用 URL 字符串的 "scheme" 部分(请参考 RFC 1738)定位 Transport 协议。

url 表示所需 Transport 的 URLName
return 关闭的 Transport 对象
ThrowsNoSuchProviderException: 如果未找到给定 URLName 的提供者。
See also javax.mail.URLName

英文文档:

getTransport

public Transport getTransport(URLName url)
                       throws NoSuchProviderException
Get a Transport object for the given URLName. If the requested Transport object cannot be obtained, NoSuchProviderException is thrown. The "scheme" part of the URL string (Refer RFC 1738) is used to locate the Transport protocol.

Parameters:
url - URLName that represents the desired Transport
Returns:
a closed Transport object
Throws:
NoSuchProviderException - If a provider for the given URLName is not found.
See Also:
URLName

public Transport getTransport(Provider provider) throws NoSuchProviderException
获取 Provider 中指定的 transport 的实例。实例化该 transport 并将其返回。
provider 将被实例化的 Transport Provider
return 实例化的 Transport
ThrowsNoSuchProviderException: 如果未找到给定 Provider 的提供者。
英文文档:

getTransport

public Transport getTransport(Provider provider)
                       throws NoSuchProviderException
Get an instance of the transport specified in the Provider. Instantiates the transport and returns it.

Parameters:
provider - Transport Provider that will be instantiated
Returns:
Instantiated Transport
Throws:
NoSuchProviderException - If provider for the given provider is not found.

public Transport getTransport(Address address) throws NoSuchProviderException
获取可将 Message 传输到指定地址类型的 Transport 对象。
address
return Transport 对象
ThrowsNoSuchProviderException: 如果未找到 Address 类型的提供者。
See also javax.mail.Address
英文文档:

getTransport

public Transport getTransport(Address address)
                       throws NoSuchProviderException
Get a Transport object that can transport a Message to the specified address type.

Parameters:
address -
Returns:
A Transport object
Throws:
NoSuchProviderException - If provider for the Address type is not found
See Also:
Address

public void setPasswordAuthentication(URLName url, PasswordAuthentication pw)
保存此(store 或 transport)URLName 的 PasswordAuthentication。如果 pw 为 null,则移除与该 URLName 对应的条目。

这通常仅供 store 或 transport 实现使用,以允许在某个会话的多次使用之间共享验证信息。

英文文档:

setPasswordAuthentication

public void setPasswordAuthentication(URLName url,
                                      PasswordAuthentication pw)
Save a PasswordAuthentication for this (store or transport) URLName. If pw is null the entry corresponding to the URLName is removed.

This is normally used only by the store or transport implementations to allow authentication information to be shared among multiple uses of a session.


public PasswordAuthentication getPasswordAuthentication(URLName url)
返回此(store 或 transport)URLName 保存的任何 PasswordAuthentication。通常仅供 store 或 transport 实现使用。
return 与该 URLName 对应的 PasswordAuthentication
英文文档:

getPasswordAuthentication

public PasswordAuthentication getPasswordAuthentication(URLName url)
Return any saved PasswordAuthentication for this (store or transport) URLName. Normally used only by store or transport implementations.

Returns:
the PasswordAuthentication corresponding to the URLName

public PasswordAuthentication requestPasswordAuthentication(java.net.InetAddress addr, int port, String protocol, String prompt, String defaultUserName)
回调应用程序以获取所需的用户名和密码。应用程序应该提供一个对话框,类似于:

Connecting to <protocol> mail service on host <addr>, port <port>.
<prompt>

User Name:<defaultUserName>
Password:
 
addr 主机的 InetAddress。可以为 null。
protocol 协议方案(比如 imap、pop3,等等)
prompt 作为提示一部分显示的其他所有 String;可以为 null。
defaultUserName 默认用户名。可以为 null。
return authenticator 收集的验证;可以为 null。
英文文档:

requestPasswordAuthentication

public PasswordAuthentication requestPasswordAuthentication(InetAddress addr,
                                                            int port,
                                                            String protocol,
                                                            String prompt,
                                                            String defaultUserName)
Call back to the application to get the needed user name and password. The application should put up a dialog something like:

 Connecting to <protocol> mail service on host <addr>, port <port>.
 <prompt>

 User Name: <defaultUserName>
 Password:
 

Parameters:
addr - InetAddress of the host. may be null.
protocol - protocol scheme (e.g. imap, pop3, etc.)
prompt - any additional String to show as part of the prompt; may be null.
defaultUserName - the default username. may be null.
Returns:
the authentication which was collected by the authenticator; may be null.

public java.util.Properties getProperties()
返回与此 Session 关联的 Properties 对象。
return Properties 对象
英文文档:

getProperties

public Properties getProperties()
Returns the Properties object associated with this Session

Returns:
Properties object

public String getProperty(String name)
返回指定属性的值。如果此属性不存在,则返回 null。
return 作为属性值的字符串
英文文档:

getProperty

public String getProperty(String name)
Returns the value of the specified property. Returns null if this property does not exist.

Returns:
String that is the property value

public void addProvider(Provider provider)
向会话添加提供者。
provider 要添加的提供者
since
JavaMail 1.4
英文文档:

addProvider

public void addProvider(Provider provider)
Add a provider to the session.

Parameters:
provider - the provider to add
Since:
JavaMail 1.4

public void setProtocolForAddress(String addresstype, String protocol)
设置用于指定类型地址的默认传输协议。默认值通常由 javamail.default.address.mapjavamail.address.map 文件或资源设置。
addresstype 地址类型
protocol 协议名称
since
JavaMail 1.4
See also getTransport(Address)
英文文档:

setProtocolForAddress

public void setProtocolForAddress(String addresstype,
                                  String protocol)
Set the default transport protocol to use for addresses of the specified type. Normally the default is set by the javamail.default.address.map or javamail.address.map files or resources.

Parameters:
addresstype - type of address
protocol - name of protocol
Since:
JavaMail 1.4
See Also:
getTransport(Address)


Submit a bug or feature

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

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

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