org.apache.geronimo.javamail.transport.smtp
Class SMTPTransport

java.lang.Object
  extended by javax.mail.Service
      extended by javax.mail.Transport
          extended by org.apache.geronimo.javamail.transport.smtp.SMTPTransport
Direct Known Subclasses:
SMTPSTransport

public class SMTPTransport
extends Transport

Simple implementation of SMTP transport. Just does plain RFC821-ish delivery.

Supported properties :

There is no way to indicate failure for a given recipient (it's possible to have a recipient address rejected). The sun impl throws exceptions even if others successful), but maybe we do a different way...

TODO : lots. ESMTP, user/pass, indicate failure, etc...

Version:
$Rev: 673649 $ $Date: 2008-07-03 06:37:56 -0400 (Thu, 03 Jul 2008) $

Field Summary
protected  SMTPConnection connection
           
protected static String DEFAULT_MAIL_HOST
           
protected static int DEFAULT_MAIL_SMTP_PORT
           
protected static int DEFAULT_MAIL_SMTPS_PORT
           
protected  org.apache.geronimo.javamail.transport.smtp.SMTPReply lastServerResponse
           
protected static String MAIL_SMTP_DSN_NOTIFY
          property keys for protocol properties.
protected static String MAIL_SMTP_EXTENSION
           
protected static String MAIL_SMTP_SENDPARTIAL
           
protected  ProtocolProperties props
           
protected  boolean sslConnection
           
 
Fields inherited from class javax.mail.Service
debug, session, url
 
Constructor Summary
  SMTPTransport(Session session, URLName name)
          Normal constructor for an SMTPTransport() object.
protected SMTPTransport(Session session, URLName name, String protocol, int defaultPort, boolean sslConnection)
          Common constructor used by the SMTPTransport and SMTPSTransport classes to do common initialization of defaults.
 
Method Summary
 void close()
          Close the connection.
 void connect(Socket socket)
          Connect to a server using an already created socket.
protected  Address[] expandGroups(Address[] addresses)
          Expand the address list by converting any group addresses into single address targets.
protected  MessagingException generateExceptionChain(SMTPConnection.SendStatus[] stats, boolean reportSuccess)
          Turn a series of send status items into a chain of exceptions indicating the state of each send operation.
protected  String getDeliveryStatusNotification(Message message)
          Determine what delivery status notification should be added to the RCPT TO: command.
 String getLocalHost()
          Retrieve the local client host name.
 boolean getReportSuccess()
          Return the current reportSuccess property.
 String getSASLRealm()
          Retrieve the SASL realm used for DIGEST-MD5 authentication.
 boolean getStartTLS()
          Return the current startTLS property.
protected  boolean protocolConnect(String host, int port, String username, String password)
          Do the protocol connection for an SMTP transport.
 void sendMessage(Message message, Address[] addresses)
          Send a message to multiple addressees.
 void setLocalHost(String localHost)
          Explicitly set the local host information.
 void setReportSuccess(boolean report)
          Set a new value for the reportSuccess property.
 void setSASLRealm(String name)
          Explicitly set the SASL realm used for DIGEST-MD5 authenticaiton.
 void setStartTLS(boolean start)
          Set a new value for the startTLS property.
 
Methods inherited from class javax.mail.Transport
addTransportListener, notifyTransportListeners, removeTransportListener, send, send
 
Methods inherited from class javax.mail.Service
addConnectionListener, connect, connect, connect, connect, finalize, getURLName, isConnected, notifyConnectionListeners, queueEvent, removeConnectionListener, setConnected, setURLName, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAIL_SMTP_DSN_NOTIFY

protected static final String MAIL_SMTP_DSN_NOTIFY
property keys for protocol properties. The actual property name will be appended with "mail." + protocol + ".", where the protocol is either "smtp" or "smtps".

See Also:
Constant Field Values

MAIL_SMTP_SENDPARTIAL

protected static final String MAIL_SMTP_SENDPARTIAL
See Also:
Constant Field Values

MAIL_SMTP_EXTENSION

protected static final String MAIL_SMTP_EXTENSION
See Also:
Constant Field Values

DEFAULT_MAIL_HOST

protected static final String DEFAULT_MAIL_HOST
See Also:
Constant Field Values

DEFAULT_MAIL_SMTP_PORT

protected static final int DEFAULT_MAIL_SMTP_PORT
See Also:
Constant Field Values

DEFAULT_MAIL_SMTPS_PORT

protected static final int DEFAULT_MAIL_SMTPS_PORT
See Also:
Constant Field Values

sslConnection

protected boolean sslConnection

props

protected ProtocolProperties props

connection

protected SMTPConnection connection

lastServerResponse

protected org.apache.geronimo.javamail.transport.smtp.SMTPReply lastServerResponse
Constructor Detail

SMTPTransport

public SMTPTransport(Session session,
                     URLName name)
Normal constructor for an SMTPTransport() object. This constructor is used to build a transport instance for the "smtp" protocol.

Parameters:
session - The attached session.
name - An optional URLName object containing target information.

SMTPTransport

protected SMTPTransport(Session session,
                        URLName name,
                        String protocol,
                        int defaultPort,
                        boolean sslConnection)
Common constructor used by the SMTPTransport and SMTPSTransport classes to do common initialization of defaults.

Parameters:
session - The host session instance.
name - The URLName of the target.
protocol - The protocol type (either "smtp" or "smtps". This helps us in retrieving protocol-specific session properties.
defaultPort - The default port used by this protocol. For "smtp", this will be 25. The default for "smtps" is 465.
sslConnection - Indicates whether an SSL connection should be used to initial contact the server. This is different from the STARTTLS support, which switches the connection to SSL after the initial startup.
Method Detail

connect

public void connect(Socket socket)
             throws MessagingException
Connect to a server using an already created socket. This connection is just like any other connection, except we will not create a new socket.

Parameters:
socket - The socket connection to use.
Throws:
MessagingException

protocolConnect

protected boolean protocolConnect(String host,
                                  int port,
                                  String username,
                                  String password)
                           throws MessagingException
Do the protocol connection for an SMTP transport. This handles server authentication, if possible. Returns false if unable to connect to the server.

Overrides:
protocolConnect in class Service
Parameters:
host - The target host name.
port - The server port number.
user - The authentication user (if any).
password - The server password. Might not be sent directly if more sophisticated authentication is used.
Returns:
true if we were able to connect to the server properly, false for any failures.
Throws:
MessagingException

sendMessage

public void sendMessage(Message message,
                        Address[] addresses)
                 throws MessagingException
Send a message to multiple addressees.

Specified by:
sendMessage in class Transport
Parameters:
message - The message we're sending.
addresses - An array of addresses to send to.
Throws:
MessagingException

getDeliveryStatusNotification

protected String getDeliveryStatusNotification(Message message)
Determine what delivery status notification should be added to the RCPT TO: command.

Parameters:
message - The message we're sending.
Returns:
The string NOTIFY= value to add to the command.

close

public void close()
           throws MessagingException
Close the connection. On completion, we'll be disconnected from the server and unable to send more data.

Overrides:
close in class Service
Throws:
MessagingException

generateExceptionChain

protected MessagingException generateExceptionChain(SMTPConnection.SendStatus[] stats,
                                                    boolean reportSuccess)
Turn a series of send status items into a chain of exceptions indicating the state of each send operation.

Parameters:
stats - The list of SendStatus items.
reportSuccess - Indicates whether we should include the report success items.
Returns:
The head of a chained list of MessagingExceptions.

expandGroups

protected Address[] expandGroups(Address[] addresses)
                          throws MessagingException
Expand the address list by converting any group addresses into single address targets.

Parameters:
addresses - The input array of addresses.
Returns:
The expanded array of addresses.
Throws:
MessagingException

getLocalHost

public String getLocalHost()
                    throws MessagingException
Retrieve the local client host name.

Returns:
The string version of the local host name.
Throws:
SMTPTransportException
MessagingException

setLocalHost

public void setLocalHost(String localHost)
Explicitly set the local host information.

Parameters:
localHost - The new localHost name.

getReportSuccess

public boolean getReportSuccess()
Return the current reportSuccess property.

Returns:
The current reportSuccess property.

setReportSuccess

public void setReportSuccess(boolean report)
Set a new value for the reportSuccess property.

Parameters:
report - The new setting.

getStartTLS

public boolean getStartTLS()
Return the current startTLS property.

Returns:
The current startTLS property.

setStartTLS

public void setStartTLS(boolean start)
Set a new value for the startTLS property.

Parameters:
start - The new setting.

getSASLRealm

public String getSASLRealm()
Retrieve the SASL realm used for DIGEST-MD5 authentication. This will either be explicitly set, or retrieved using the mail.smtp.sasl.realm session property.

Returns:
The current realm information (which can be null).

setSASLRealm

public void setSASLRealm(String name)
Explicitly set the SASL realm used for DIGEST-MD5 authenticaiton.

Parameters:
name - The new realm name.


Copyright © 2003-2009 The Apache Software Foundation. All Rights Reserved.