|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.mail.Service
javax.mail.Transport
com.sun.mail.smtp.SMTPTransport
public class SMTPTransport
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.
ConnectionEvent
,
TransportEvent
Field Summary |
---|
Fields inherited from class javax.mail.Service |
---|
debug, session, url |
Constructor Summary | |
---|---|
|
SMTPTransport(Session session,
URLName urlname)
Constructor that takes a Session object and a URLName that represents a specific SMTP server. |
protected |
SMTPTransport(Session session,
URLName urlname,
java.lang.String name,
int defaultPort,
boolean isSSL)
Constructor used by this class and by SMTPSSLTransport subclass. |
Method Summary | |
---|---|
void |
close()
Close the server and terminate its connection |
void |
connect(java.net.Socket socket)
Start the SMTP protocol on the given socket, which was already connected by the caller. |
protected void |
finalize()
Stop the event dispatcher thread so the queue can be garbage collected. |
java.lang.String |
getExtensionParameter(java.lang.String ext)
Return the parameter the server provided for the specified service extension, or null if the extension isn't supported. |
java.lang.String |
getLastServerResponse()
Return the last response we got from the server. |
java.lang.String |
getLocalHost()
Get the name of the local host, for use in the EHLO and HELO commands. |
boolean |
getReportSuccess()
Should we report even successful sends by throwing an exception? If so, a SendFailedException will always be thrown and
an SMTPAddressSucceededException will be included in the exception
chain for each successful address, along with the usual
SMTPAddressFailedException for each unsuccessful address. |
java.lang.String |
getSASLRealm()
Gets the SASL realm to be used for DIGEST-MD5 authentication. |
boolean |
getStartTLS()
Should we use the STARTTLS command to secure the connection if the server supports it? |
boolean |
getUseRset()
Should we use the RSET command instead of the NOOP command in the @{link #isConnected isConnected} method? |
boolean |
isConnected()
Check whether the transport is connected. |
protected boolean |
protocolConnect(java.lang.String host,
int port,
java.lang.String user,
java.lang.String passwd)
Performs the actual protocol-specific connection attempt. |
void |
sendMessage(Message message,
Address[] addresses)
Send the Message to the specified list of addresses. |
void |
setLocalHost(java.lang.String localhost)
Set the name of the local host, for use in the EHLO and HELO commands. |
void |
setReportSuccess(boolean reportSuccess)
Set whether successful sends should be reported by throwing an exception. |
void |
setSASLRealm(java.lang.String saslRealm)
Sets the SASL realm to be used for DIGEST-MD5 authentication. |
void |
setStartTLS(boolean useStartTLS)
Set whether the STARTTLS command should be used. |
void |
setUseRset(boolean useRset)
Set whether the RSET command should be used instead of the NOOP command in the @{link #isConnected isConnected} method. |
boolean |
supportsExtension(java.lang.String ext)
Return true if the SMTP server supports the specified service extension. |
Methods inherited from class javax.mail.Transport |
---|
addTransportListener, notifyTransportListeners, removeTransportListener, send, send |
Methods inherited from class javax.mail.Service |
---|
addConnectionListener, connect, connect, connect, connect, getURLName, notifyConnectionListeners, queueEvent, removeConnectionListener, setConnected, setURLName, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public SMTPTransport(Session session, URLName urlname)
protected SMTPTransport(Session session, URLName urlname, java.lang.String name, int defaultPort, boolean isSSL)
Method Detail |
---|
public java.lang.String getLocalHost()
public void setLocalHost(java.lang.String localhost)
public void connect(java.net.Socket socket) throws MessagingException
MessagingException
public java.lang.String getSASLRealm()
public void setSASLRealm(java.lang.String saslRealm)
saslRealm
- the name of the realm to use for
SASL authentication.public boolean getReportSuccess()
SendFailedException
will always be thrown and
an SMTPAddressSucceededException
will be included in the exception
chain for each successful address, along with the usual
SMTPAddressFailedException
for each unsuccessful address.
public void setReportSuccess(boolean reportSuccess)
reportSuccess
- should we throw an exception on success?public boolean getStartTLS()
public void setStartTLS(boolean useStartTLS)
useStartTLS
- should we use the STARTTLS command?public boolean getUseRset()
public void setUseRset(boolean useRset)
useRset
- should we use the RSET command?public java.lang.String getLastServerResponse()
protected boolean protocolConnect(java.lang.String host, int port, java.lang.String user, java.lang.String passwd) throws MessagingException
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).
protocolConnect
in class Service
host
- the name of the host to connect toport
- the port to use (-1 means use default port)user
- the name of the user to login aspasswd
- the user's password
MessagingException
- for non-authentication failurespublic void sendMessage(Message message, Address[] addresses) throws MessagingException, SendFailedException
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.
sendMessage
in class Transport
message
- The MimeMessage to be sentaddresses
- 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.TransportEvent
public void close() throws MessagingException
close
in class Service
MessagingException
- for errors while closingConnectionEvent
public boolean isConnected()
isConnected
in class Service
protected void finalize() throws java.lang.Throwable
Service
finalize
in class Service
java.lang.Throwable
public boolean supportsExtension(java.lang.String ext)
ext
- the service extension name
public java.lang.String getExtensionParameter(java.lang.String ext)
ext
- the service extension name
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |