| java.lang.Object | |||
| ↳ | com.google.code.javax.mail.Service | ||
| ↳ | com.google.code.javax.mail.Transport | ||
| ↳ | com.google.code.com.sun.mail.smtp.SMTPTransport | ||
Known Direct Subclasses
|
This class implements the Transport abstract class using SMTP for message submission and transport.
See the com.sun.mail.smtp package documentation for further information on the SMTP protocol provider.
This class includes many protected methods that allow a subclass to
extend this class and add support for non-standard SMTP commands.
The issueCommand(String, int) and sendCommand(String) methods can be
used to send simple SMTP commands. Other methods such as the
mailFrom() and data() methods can be overridden to
insert new commands before or after the corresponding SMTP commands.
For example, a subclass could do this to send the XACT command
before sending the DATA command:
protected OutputStream data() throws MessagingException {
if (supportsExtension("XACCOUNTING"))
issueCommand("XACT", 25);
return super.data();
}
| Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| String | UNKNOWN | ||||||||||
| Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| CRLF | |||||||||||
| UNKNOWN_SA | |||||||||||
| addresses | |||||||||||
| authenticators | |||||||||||
| authorizationID | |||||||||||
| dataStream | |||||||||||
| defaultAuthenticationMechanisms | |||||||||||
| defaultPort | |||||||||||
| enableSASL | |||||||||||
| exception | |||||||||||
| extMap | |||||||||||
| hexchar | |||||||||||
| host | |||||||||||
| ignoreList | Headers that should not be included when sending | ||||||||||
| invalidAddr | |||||||||||
| isSSL | |||||||||||
| lastReturnCode | |||||||||||
| lastServerResponse | |||||||||||
| lineInputStream | |||||||||||
| localHostName | |||||||||||
| message | |||||||||||
| name | |||||||||||
| noopStrict | |||||||||||
| notificationDone | |||||||||||
| ntlmDomain | |||||||||||
| out | |||||||||||
| quitWait | |||||||||||
| reportSuccess | |||||||||||
| requireStartTLS | |||||||||||
| saslAuthenticator | |||||||||||
| saslMechanisms | |||||||||||
| saslRealm | |||||||||||
| sendPartiallyFailed | |||||||||||
| serverInput | |||||||||||
| serverOutput | |||||||||||
| serverSocket | |||||||||||
| useRset | |||||||||||
| useStartTLS | |||||||||||
| validSentAddr | |||||||||||
| validUnsentAddr | |||||||||||
|
[Expand]
Inherited Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
com.google.code.javax.mail.Transport
| |||||||||||
From class
com.google.code.javax.mail.Service
| |||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Constructor that takes a Session object and a URLName
that represents a specific SMTP server.
| |||||||||||
| Protected Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Constructor used by this class and by SMTPSSLTransport subclass.
| |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Close the Transport and terminate the connection to the server.
| |||||||||||
Start the SMTP protocol on the given socket, which was already
connected by the caller.
| |||||||||||
Gets the authorization ID to be used for authentication.
| |||||||||||
Return the parameter the server provided for the specified
service extension, or null if the extension isn't supported.
| |||||||||||
Return the return code from the last response we got from the server.
| |||||||||||
Return the last response we got from the server.
| |||||||||||
Get the name of the local host, for use in the EHLO and HELO commands.
| |||||||||||
Gets the NTLM domain to be used for NTLM authentication.
| |||||||||||
Is the NOOP command required to return a response code
of 250 to indicate success?
| |||||||||||
Should we report even successful sends by throwing an exception?
If so, a
SendFailedException will always be thrown and
an com.sun.mail.smtp.SMTPAddressSucceededException
SMTPAddressSucceededException will be included in the exception
chain for each successful address, along with the usual
com.sun.mail.smtp.SMTPAddressFailedException
SMTPAddressFailedException for each unsuccessful address. | |||||||||||
Should we require the STARTTLS command to secure the connection?
| |||||||||||
Is SASL authentication enabled?
| |||||||||||
Get the list of SASL mechanisms to consider if SASL authentication
is enabled.
| |||||||||||
Gets the SASL realm to be used for DIGEST-MD5 authentication.
| |||||||||||
Should we use the STARTTLS command to secure the connection
if the server supports it?
| |||||||||||
Should we use the RSET command instead of the NOOP command
in the @{link #isConnected isConnected} method?
| |||||||||||
Check whether the transport is connected.
| |||||||||||
Send the command to the server.
| |||||||||||
SASL-based login.
| |||||||||||
Send the Message to the specified list of addresses.
| |||||||||||
Sets the authorization ID to be used for authentication.
| |||||||||||
Set the name of the local host, for use in the EHLO and HELO commands.
| |||||||||||
Sets the NTLM domain to be used for NTLM authentication.
| |||||||||||
Set whether the NOOP command is required to return a response code
of 250 to indicate success.
| |||||||||||
Set whether successful sends should be reported by throwing
an exception.
| |||||||||||
Set whether the STARTTLS command should be required.
| |||||||||||
Set whether SASL authentication is enabled.
| |||||||||||
Set the list of SASL mechanisms to consider if SASL authentication
is enabled.
| |||||||||||
Sets the SASL realm to be used for DIGEST-MD5 authentication.
| |||||||||||
Set whether the STARTTLS command should be used.
| |||||||||||
Set whether the RSET command should be used instead of the
NOOP command in the @{link #isConnected isConnected} method.
| |||||||||||
Send the command to the server and return the response code
from the server.
| |||||||||||
Return true if the SMTP server supports the specified service
extension.
| |||||||||||
| Protected Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Check if we're in the connected state.
| |||||||||||
Send the
DATA command to the SMTP host and return
an OutputStream to which the data is to be written. | |||||||||||
Issue the
EHLO command. | |||||||||||
Stop the event dispatcher thread so the queue can be garbage collected.
| |||||||||||
Terminate the sent data.
| |||||||||||
Issue the
HELO command. | |||||||||||
Issue the
MAIL FROM: command to start sending a message. | |||||||||||
Notify all TransportListeners.
| |||||||||||
Performs the actual protocol-specific connection attempt.
| |||||||||||
Sends each address to the SMTP host using the
RCPT TO:
command and copies the address either into
the validSentAddr or invalidAddr arrays. | |||||||||||
Reads server reponse returning the
returnCode
as the number. | |||||||||||
Sends command
cmd to the server terminating
it with CRLF. | |||||||||||
Send the command to the server and return the response code
from the server.
| |||||||||||
Issue the
STARTTLS command and switch the socket to
TLS mode if it succeeds. | |||||||||||
Does the server we're connected to support the specified
authentication mechanism? Uses the extension information
returned by the server from the EHLO command.
| |||||||||||
Convert a string to RFC 1891 xtext format.
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
com.google.code.javax.mail.Transport
| |||||||||||
From class
com.google.code.javax.mail.Service
| |||||||||||
From class
java.lang.Object
| |||||||||||
Headers that should not be included when sending
Constructor that takes a Session object and a URLName that represents a specific SMTP server.
| session | |
|---|---|
| urlname |
Constructor used by this class and by SMTPSSLTransport subclass.
| session | |
|---|---|
| urlname | |
| name | |
| isSSL |
Close the Transport and terminate the connection to the server.
| MessagingException |
|---|
Start the SMTP protocol on the given socket, which was already connected by the caller. Useful for implementing the SMTP ATRN command (RFC 2645) where an existing connection is used when the server reverses roles and becomes the client.
| socket |
|---|
| MessagingException |
|---|
Gets the authorization ID to be used for authentication.
Return the parameter the server provided for the specified service extension, or null if the extension isn't supported.
| ext | The service extension name |
|---|
Return the return code from the last response we got from the server.
Return the last response we got from the server. A failed send is often followed by an RSET command, but the response from the RSET command is not saved. Instead, this returns the response from the command before the RSET command.
Get the name of the local host, for use in the EHLO and HELO commands. The property mail.smtp.localhost overrides mail.smtp.localaddress, which overrides what InetAddress would tell us.
Gets the NTLM domain to be used for NTLM authentication.
Is the NOOP command required to return a response code of 250 to indicate success?
Should we report even successful sends by throwing an exception?
If so, a SendFailedException will always be thrown and
an com.sun.mail.smtp.SMTPAddressSucceededException
SMTPAddressSucceededException will be included in the exception
chain for each successful address, along with the usual
com.sun.mail.smtp.SMTPAddressFailedException
SMTPAddressFailedException for each unsuccessful address.
Should we require the STARTTLS command to secure the connection?
Is SASL authentication enabled?
Get the list of SASL mechanisms to consider if SASL authentication is enabled. If the list is empty or null, all available SASL mechanisms are considered.
Gets the SASL realm to be used for DIGEST-MD5 authentication.
Should we use the STARTTLS command to secure the connection if the server supports it?
Should we use the RSET command instead of the NOOP command in the @{link #isConnected isConnected} method?
Check whether the transport is connected. Override superclass method, to actually ping our server connection.
Send the command to the server. If the expected response code is not received, throw a MessagingException.
| cmd | The command to send |
|---|---|
| expect | The expected response code (-1 means don't care) |
| MessagingException |
|---|
Send the Message to the specified list of addresses.
If all the addresses succeed the SMTP check
using the RCPT TO: command, we attempt to send the message.
A TransportEvent of type MESSAGE_DELIVERED is fired indicating the
successful submission of a message to the SMTP host.
If some of the addresses fail the SMTP check,
and the mail.stmp.sendpartial property is not set,
sending is aborted. The TransportEvent of type MESSAGE_NOT_DELIVERED
is fired containing the valid and invalid addresses. The
SendFailedException is also thrown.
If some of the addresses fail the SMTP check,
and the mail.stmp.sendpartial property is set to true,
the message is sent. The TransportEvent of type
MESSAGE_PARTIALLY_DELIVERED
is fired containing the valid and invalid addresses. The
SMTPSendFailedException is also thrown.
MessagingException is thrown if the message can't write out
an RFC822-compliant stream using its writeTo method.
| message | The MimeMessage to be sent |
|---|---|
| addresses | List of addresses to send this message to |
| SMTPSendFailedException | if the send failed because of an SMTP command error |
|---|---|
| SendFailedException | if the send failed because of invalid addresses. |
| MessagingException | if the connection is dead or not in the connected state or if the message is not a MimeMessage. |
Sets the authorization ID to be used for authentication.
| authzid | The authorization ID to use for authentication. |
|---|
Set the name of the local host, for use in the EHLO and HELO commands.
| localhost |
|---|
Sets the NTLM domain to be used for NTLM authentication.
| ntlmDomain | The name of the domain to use for NTLM authentication. |
|---|
Set whether the NOOP command is required to return a response code of 250 to indicate success.
| noopStrict | Is NOOP required to return 250? |
|---|
Set whether successful sends should be reported by throwing an exception.
| reportSuccess | Should we throw an exception on success? |
|---|
Set whether the STARTTLS command should be required.
| requireStartTLS | Should we require the STARTTLS command? |
|---|
Set whether SASL authentication is enabled.
| enableSASL | Should we enable SASL authentication? |
|---|
Set the list of SASL mechanisms to consider if SASL authentication is enabled. If the list is empty or null, all available SASL mechanisms are considered.
| mechanisms | The array of SASL mechanisms to consider |
|---|
Sets the SASL realm to be used for DIGEST-MD5 authentication.
| saslRealm | The name of the realm to use for SASL authentication. |
|---|
Set whether the STARTTLS command should be used.
| useStartTLS | Should we use the STARTTLS command? |
|---|
Set whether the RSET command should be used instead of the NOOP command in the @{link #isConnected isConnected} method.
| useRset | Should we use the RSET command? |
|---|
Send the command to the server and return the response code from the server.
| cmd |
|---|
| MessagingException |
|---|
Return true if the SMTP server supports the specified service extension. Extensions are reported as results of the EHLO command when connecting to the server. See RFC 1869 and other RFCs that define specific extensions.
| ext | The service extension name |
|---|
Check if we're in the connected state. Don't bother checking whether the server is still alive, that will be detected later.
| IllegalStateException | if not connected |
|---|
Send the DATA command to the SMTP host and return
an OutputStream to which the data is to be written.
| MessagingException |
|---|
Issue the EHLO command.
Collect the returned list of service extensions.
| domain | Our domain |
|---|
| MessagingException |
|---|
Stop the event dispatcher thread so the queue can be garbage collected.
| Throwable |
|---|
Issue the MAIL FROM: command to start sending a message.
Gets the sender's address in the following order:
| MessagingException |
|---|
Notify all TransportListeners. Keep track of whether notification has been done so as to only notify once per send.
| type | |
|---|---|
| validSent | |
| validUnsent | |
| invalid | |
| msg |
Performs the actual protocol-specific connection attempt. Will attempt to connect to "localhost" if the host was null.
Unless mail.smtp.ehlo is set to false, we'll try to identify ourselves using the ESMTP command EHLO. If mail.smtp.auth is set to true, we insist on having a username and password, and will try to authenticate ourselves if the server supports the AUTH extension (RFC 2554).
| host | The name of the host to connect to |
|---|---|
| port | The port to use (-1 means use default port) |
| user | The name of the user to login as |
| passwd | The user's password |
| MessagingException | for non-authentication failures |
|---|
Sends each address to the SMTP host using the RCPT TO:
command and copies the address either into
the validSentAddr or invalidAddr arrays.
Sets the sendFailed
flag to true if any addresses failed.
| MessagingException |
|---|
Reads server reponse returning the returnCode
as the number. Returns -1 on failure. Sets
lastServerResponse and lastReturnCode.
| MessagingException |
|---|
Send the command to the server and return the response code from the server.
| cmd |
|---|
| MessagingException |
|---|
Issue the STARTTLS command and switch the socket to
TLS mode if it succeeds.
| MessagingException |
|---|
Does the server we're connected to support the specified authentication mechanism? Uses the extension information returned by the server from the EHLO command.
| auth | The authentication mechanism |
|---|
Convert a string to RFC 1891 xtext format.
xtext = *( xchar / hexchar )
xchar = any ASCII CHAR between "!" (33) and "~" (126) inclusive,
except for "+" and "=".
; "hexchar"s are intended to encode octets that cannot appear
; as ASCII characters within an esmtp-value.
hexchar = ASCII "+" immediately followed by two upper case
hexadecimal digits
| s |
|---|