Javamail-api-imap-servers

提供:Dev Guides
移動先:案内検索

JavaMail API-IMAPサーバー

IMAPは Internet Message Access Protocol の頭字語です。 これは、電子メールクライアントがリモートメールサーバー上の電子メールにアクセスできるようにするアプリケーション層インターネットプロトコルです。 IMAPサーバーは通常、既知のポート143でリッスンします。 IMAP over SSL(IMAPS)はポート番号993に割り当てられます。

IMAPは、オンラインとオフラインの両方の操作モードをサポートしています。 IMAPを使用する電子メールクライアントは、通常、ユーザーがメッセージを明示的に削除するまでサーバーにメッセージを残します。

パッケージ com.sun.mail.imap は、IMAPメッセージストアへのアクセスを提供するJavaMail APIのIMAPプロトコルプロバイダーです。 次の表に、このプロバイダーのインターフェイスとクラスを示します。

Class/Interface Description
IMAPFolder.ProtocolCommand This a simple interface for user-defined IMAP protocol commands.
ACL This is a class. An access control list entry for a particular authentication identifier (user or group).
IMAPFolder This class implements an IMAP folder.
IMAPFolder.FetchProfileItem This a class for fetching headers.
IMAPMessage This class implements an ReadableMime object.
IMAPMessage.FetchProfileCondition This class implements the test to be done on each message in the folder.
IMAPSSLStore This class provides access to an IMAP message store over SSL.
IMAPStore This class provides access to an IMAP message store.
Rights This class represents the set of rights for an authentication identifier (for instance, a user or a group).
Rights.Right This inner class represents an individual right.
SortTerm A particular sort criteria, as defined by RFC 5256.

このプロバイダーの上に注意すべきいくつかのポイント:

  • このプロバイダーは、IMAP4プロトコルとIMAP4rev1プロトコルの両方をサポートしています。
  • 接続されたIMAPStoreは、IMAPサーバーとの通信に使用するIMAPプロトコルオブジェクトのプールを保持します。 フォルダーが開かれ、新しいIMAPプロトコルオブジェクトが必要になると、IMAPStoreはそれらを接続プールから提供するか、使用できない場合は作成します。 フォルダーが閉じられると、そのIMAPプロトコルオブジェクトがプールの場合、接続プールに返されます。 *接続されたIMAPStoreオブジェクトは、ストアにIMAPサーバーへの専用接続を提供する個別のIMAPプロトコルオブジェクトを保持する場合と保持しない場合があります。

IMAPプロトコルプロバイダーは、JavaMail Sessionオブジェクトで設定できる以下のプロパティをサポートします。 プロパティは常に文字列として設定されます。* Type *列は、文字列の解釈方法を説明しています。

Name Type Description
mail.imap.user String Default user name for IMAP.
mail.imap.host String The IMAP server to connect to.
mail.imap.port int The IMAP server port to connect to, if the connect() method doesn’t explicitly specify one. Defaults to 143.
mail.imap.partialfetch boolean Controls whether the IMAP partial-fetch capability should be used. Defaults to true.
mail.imap.fetchsize int Partial fetch size in bytes. Defaults to 16K.
mail.imap.ignorebodystructuresize boolean The IMAP BODYSTRUCTURE response includes the exact size of each body part. Normally, this size is used to determine how much data to fetch for each body part. Defaults to false.
mail.imap.connectiontimeout int Socket connection timeout value in milliseconds. Default is infinite timeout.
mail.imap.timeout int Socket I/O timeout value in milliseconds. Default is infinite timeout.
mail.imap.statuscachetimeout int Timeout value in milliseconds for cache of STATUS command response. Default is 1000 (1 second). Zero disables cache.
mail.imap.appendbuffersize int Maximum size of a message to buffer in memory when appending to an IMAP folder.
mail.imap.connectionpoolsize int Maximum number of available connections in the connection pool. Default is 1.
mail.imap.connectionpooltimeout int Timeout value in milliseconds for connection pool connections. Default is 45000 (45 seconds).
mail.imap.separatestoreconnection boolean Flag to indicate whether to use a dedicated store connection for store commands. Default is false.
mail.imap.auth.login.disable boolean If true, prevents use of the non-standard AUTHENTICATE LOGIN command, instead using the plain LOGIN command. Default is false.
mail.imap.auth.plain.disable boolean If true, prevents use of the AUTHENTICATE PLAIN command. Default is false.
mail.imap.auth.ntlm.disable boolean If true, prevents use of the AUTHENTICATE NTLM command. Default is false.
mail.imap.proxyauth.user String If the server supports the PROXYAUTH extension, this property specifies the name of the user to act as. Authenticate to the server using the administrator’s credentials. After authentication, the IMAP provider will issue the PROXYAUTH command with the user name specified in this property.
mail.imap.localaddress String Local address (host name) to bind to when creating the IMAP socket. Defaults to the address picked by the Socket class.
mail.imap.localport int Local port number to bind to when creating the IMAP socket. Defaults to the port number picked by the Socket class.
mail.imap.sasl.enable boolean If set to true, attempt to use the javax.security.sasl package to choose an authentication mechanism for login. Defaults to false.
mail.imap.sasl.mechanisms String A space or comma separated list of SASL mechanism names to try to use.
mail.imap.sasl.authorizationid String The authorization ID to use in the SASL authentication. If not set, the authentication ID (user name) is used.
mail.imap.sasl.realm String The realm to use with SASL authentication mechanisms that require a realm, such as DIGEST-MD5.
mail.imap.auth.ntlm.domain String The NTLM authentication domain.
mail.imap.auth.ntlm.flags int NTLM protocol-specific flags.
mail.imap.socketFactory Socket Factory If set to a class that implements the javax.net.SocketFactory interface, this class will be used to create IMAP sockets.
mail.imap.socketFactory.class String If set, specifies the name of a class that implements the javax.net.SocketFactory interface. This class will be used to create IMAP sockets.
mail.imap.socketFactory.fallback boolean If set to true, failure to create a socket using the specified socket factory class will cause the socket to be created using the java.net.Socket class. Defaults to true.
mail.imap.socketFactory.port int Specifies the port to connect to when using the specified socket factory. Default port is used when not set.
mail.imap.ssl.enable boolean If set to true, use SSL to connect and use the SSL port by default. Defaults to false for the "imap" protocol and true for the "imaps" protocol.
mail.imap.ssl.checkserveridentity boolean If set to true, check the server identity as specified by RFC 2595. Defaults to false.
mail.imap.ssl.trust String If set, and a socket factory hasn’t been specified, enables use of a MailSSLSocketFactory. If set to "*", all hosts are trusted. If set to a whitespace separated list of hosts, those hosts are trusted. Otherwise, trust depends on the certificate the server presents.
mail.imap.ssl.socketFactory SSL Socket Factory If set to a class that extends the javax.net.ssl.SSLSocketFactory class, this class will be used to create IMAP SSL sockets.
mail.imap.ssl.socketFactory.class String If set, specifies the name of a class that extends the javax.net.ssl.SSLSocketFactory class. This class will be used to create IMAP SSL sockets.
mail.imap.ssl.socketFactory.port int Specifies the port to connect to when using the specified socket factory. If not set, the default port will be used.
mail.imap.ssl.protocols string Specifies the SSL protocols that will be enabled for SSL connections. The property value is a whitespace separated list of tokens acceptable to the javax.net.ssl.SSLSocket.setEnabledProtocols method.
mail.imap.starttls.enable boolean If true, enables the use of the STARTTLS command (if supported by the server) to switch the connection to a TLS-protected connection before issuing any login commands. Default is false.
mail.imap.starttls.required boolean If true, requires the use of the STARTTLS command. If the server doesn’t support the STARTTLS command, or the command fails, the connect method will fail. Defaults to false.
mail.imap.socks.host string Specifies the host name of a SOCKS5 proxy server that will be used for connections to the mail server.
mail.imap.socks.port string Specifies the port number for the SOCKS5 proxy server. This should only need to be used if the proxy server is not using the standard port number of 1080.
mail.imap.minidletime int This property sets the delay in milliseconds. If not set, the default is 10 milliseconds.
mail.imap.enableimapevents boolean Enable special IMAP-specific events to be delivered to the Store’s ConnectionListener. If true, unsolicited responses received during the Store’s idle method will be sent as ConnectionEvents with a type of IMAPStore.RESPONSE. The event’s message will be the raw IMAP response string. By default, these events are not sent.
mail.imap.folder.class String Class name of a subclass of com.sun.mail.imap.IMAPFolder. The subclass can be used to provide support for additional IMAP commands. The subclass must have public constructors of the form public MyIMAPFolder(String fullName, char separator, IMAPStore store, Boolean isNamespace) and public MyIMAPFolder(ListInfo li, IMAPStore store)

一般に、アプリケーションはこのパッケージのクラスを直接使用する必要はありません。 代わりに、javax.mailパッケージ(およびサブパッケージ)で定義されたAPIを使用する必要があります。 アプリケーションは、IMAPStoreまたはIMAPFolderのインスタンスを直接構築しないでください。 代わりに、SessionメソッドgetStoreを使用して適切なStoreオブジェクトを取得し、そこからFolderオブジェクトを取得する必要があります。

IMAPサーバーの使用例は、リンク:/javamail_api/javamail_api_quota_management [Quota Management]で説明されています。