メッセージを送信時、SendFailedException
でスローされる失敗したそれぞれのアドレスの詳細情報はトップレベルからチェーンされた
SMTPAddressFailedException
で利用できます。
更に、mail.smtp.reportsuccess
プロパティが設定された場合、
SMTPAddressSucceededException
はそれぞれの成功したアドレスのリストに含まれます。
トップレベルから
SendFailedException
をスローする事に注意して下さい。
又、SMTP プロバイダは ESMTP をサポートします(RFC 1651)。 それは、LOGIN、PLAIN、及び DIGEST-MD5 メカニズム (RFC 2592 及び RFC 2831) を使用して SMTP 認証 (RFC 2554) を任意に使用することができます。
SMTP 認証を使用する場合、SMTP サーバに接続するユーザ名とパスワードを SMTP Transport に指定する必要があります。 以下のアプローチの何れかを使用します:
mail.smtp.user
プロパティでコールバックの為のデフォルトユーザ名を提供する様に設定することができます。
しかし、パスワードを明示的に指定する必要がある事に注意して下さい。
このアプローチは、メッセージを送る静的な Transport send
メソッドを使用します。
connect
をメソッドと呼び出します。
このアプローチは、明示的に Transport オブジェクトを管理して、メッセージを送る Transport sendMessage
メソッドの使用を必要とします。
transport.java デモプログラムはどの様に Transport オブジェクトを管理するかを示します。
以下は、およそ静的な Transport send
メソッドに同等ですが、必要なユーザ名とパスワードを提供します:
Transport tr = session.getTransport("smtp"); tr.connect(smtphost, username, password); msg.saveChanges(); // これを忘れないで下さい tr.sendMessage(msg, msg.getAllRecipients()); tr.close();
又、DIGEST-MD5 認証を使用する場合、適切なレルムを供給する必要があります。
メールサーバ管理者はこの情報を提供することができます。
mail.smtp.saslrealm
プロパティ
、又は SMTPTransport
の setSASLRealm
メソッドを使用して設定する事ができます。
又、SMTP は 任意に Delivery Status Notifications を要求する事ができます
(RFC 1891)。
配送状態は、"multipart/report"
(RFC 1892)
パートと共に "message/delivery-status"
(RFC 1894)
メッセージタイプを使用することで通知されます。
JavaMail は現在これらの新しい MIME タイプのダイレクトサポートを提供していませんが、
MimeMultipart
と MimeMessage
オブジェクトを使用して、
"multipart" 又は "message" コンテンツとしてそれらを処理する事が可能です。
これらの機能を有効にするには以下を参照してプロパティを設定して下さい。
注意 これらの機能を説明する文章はここにはありません!!! これらの機能が何をするのか、そして、どの様にそれらを使用するかを理解する為に前述の様に適切な RFC を読む必要があります。 ただプロパティを設定し始めないで下さい。そして、それが働くと予想するように働いていない場合に、私たちに不平を言ってください。 まず始めに RFC 群を読んで下さい!!!
SMTP プロトコルプロバイダは以下のプロパティをサポートします。
(プロパティは JavaMail Session
オブジェクトに設定される場合があります)
プロパティは常に文字列として設定します。型は文字列がどの様に解釈されるかを説明します。
使用例
props.put("mail.smtp.port", "888");
mail.smtp.port
のプロパティを設定します。(int 型のプロパティ)
名前 | 型 | 説明 |
---|---|---|
mail.smtp.user | String | SMTP のデフォルトユーザ名 |
mail.smtp.host | String | 接続する SMTP サーバ |
mail.smtp.port | int | 接続する AMTP サーバのポート番号。connect() メソッドで明示的に指定しない場合のデフォルトは 25 です。 |
mail.smtp.connectiontimeout | int | ミリ秒で表現されるソケット接続のタイムアウト値。デフォルトは無限(タイムアウトしない)です。 |
mail.smtp.timeout | int | ミリ秒で表現されるソケット I/O のタイムアウト値。デフォルトは無限(タイムアウトしない)です。 |
mail.smtp.from | String | SMTP MAIL コマンドに使用する Eメールアドレスです。 This sets the envelope return address. デフォルトは msg.getFrom() 又は InternetAddress.getLocalAddress() です。 NOTE: mail.smtp.user は以前これが使用されました。 |
mail.smtp.localhost | String | ローカルホスト名 デフォルトは InetAddress.getLocalHost().getHostName() です。 JDK とネームサービスが適切に構成されている場合、通常は設定する必要はありません。 |
mail.smtp.localaddress | String | SMTP ソケット作成時にバインドさせるローカルアドレス(ホスト名)です。 Defaults to the address picked by the Socket class. Should not normally need to be set, but useful with multi-homed hosts where it's important to pick a particular local address to bind to. |
mail.smtp.localport | int | SMTP ソケット作成時にバインドさせるローカルポート番号です。 Defaults to the port number picked by the Socket class. |
mail.smtp.ehlo | boolean | false の場合、EHLO コマンドを試行しません。 デフォルトは true です。 Normally failure of the EHLO command will fallback to the HELO command; このプロパティは適切に EHLO に失敗しない、又は適切に EHLO を実装しないサーバの為だけに存在します。 |
mail.smtp.auth | boolean | true の場合、AUTH コマンドを使用してユーザを認証を行います。 デフォルトは false です。 |
mail.smtp.submitter | String | The submitter to use in the AUTH tag in the MAIL FROM command. Typically used by a mail relay to pass along information about the original submitter of the message. See also the setSubmitter method of SMTPMessage. Mail clients typically do not use this. |
mail.smtp.dsn.notify | String | RCPT コマンドの NOTIFY オプションです。 Either NEVER 又は SUCCESS、FAILURE、及び DELAY の何れかの組み合わせ。 |
mail.smtp.dsn.ret | String | MAIL コマンドの RET オプションです。 FULL 又は HDRS のどちらか |
mail.smtp.allow8bitmime | boolean | If set to true, and the server supports the 8BITMIME extension, text parts of messages that use the "quoted-printable" or "base64" encodings are converted to use "8bit" encoding if they follow the RFC2045 rules for 8bit text. |
mail.smtp.sendpartial | boolean | If set to true, and a message has some valid and some invalid addresses, send the message anyway, reporting the partial failure with a SendFailedException. If set to false (the default), the message is not sent to any of the recipients if there is an invalid recipient address. |
mail.smtp.saslrealm | String | DIGEST-MD5 認証と共に使用するレルムです。 |
mail.smtp.quitwait | boolean | If set to true, causes the transport to wait for the response to the QUIT command. If set to false (the default), the QUIT command is sent and the connection is immediately closed. (NOTE: The default may change in the next release.) |
mail.smtp.reportsuccess | boolean | If set to true, causes the transport to include an SMTPAddressSucceededException for each address that is successful. Note also that this will cause a SendFailedException to be thrown from the sendMessage method of SMTPTransport even if all addresses were correct and the message was sent successfully. |
mail.smtp.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 SMTP sockets. |
mail.smtp.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. デフォルトは true です。 |
mail.smtp.socketFactory.port | int | Specifies the port to connect to when using the specified socket factory. 設定しない場合はこのプロトコルのデフォルトポート番号が使用されます。 |
mail.smtp.mailextension | String | MAIL コマンドに追加する拡張文字列 The extension string can be used to specify standard SMTP service extensions as well as vendor-specific extensions. Typically the application should use the SMTPTransport method supportsExtension to verify that the server supports the desired service extension. 特定の拡張を定義する RFC1869 と 他のRFC を参照して下さい。 |
mail.smtp.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. Note that an appropriate trust store must configured so that the client will trust the server's certificate. Defaults to false. |
mail.smtp.userset | boolean | If set to true, use the RSET command instead of the NOOP command in the isConnected method. In some cases sendmail will respond slowly after many NOOP commands; use of RSET avoids this sendmail issue. Defaults to false. |
一般的には、アプリケーションはこのパッケージ中のクラスを直接使用する必要はないはずです。
代わりに javax.mail
パッケージ(とサブパッケージ)で定義された API を使用すべきです。
アプリケーションは SMTPTransport
のインスタンスを決して直接構成するべきではありません。
代わりに適切な Transport
オブジェクトを入手する Session
の getTransport
メソッドを使用すべきです。
警告: このパッケージのユニークな API は実験的であると考えるべきです。 将来、現在の API を使用するアプリケーションと両立しない方法でそれらを変えるかもしれません。