com.openexchange.mail.transport
Class MailTransport

java.lang.Object
  extended by com.openexchange.mail.transport.MailTransport

public abstract class MailTransport
extends java.lang.Object

MailTransport - Provides operations related to a mail transport.

Author:
Thorben Betten

Constructor Summary
MailTransport()
           
 
Method Summary
abstract  void close()
          Closes this mail transport
static MailTransport getInstance(com.openexchange.session.Session session)
          Gets the proper instance of mail transport parameterized with given session.
static MailTransport getInstance(com.openexchange.session.Session session, int accountId)
          Gets the proper instance of mail transport for session user's default transport account.
abstract  TransportConfig getTransportConfig()
          Returns the transport configuration appropriate for current user.
abstract  void ping()
          Pings the transport server to check if a connection can be established.
 MailMessage sendMailMessage(ComposedMailMessage transportMail, ComposeType sendType)
          Sends a mail message This is a convenience method that invokes sendMailMessage(ComposedMailMessage, ComposeType, Address[]) with the latter parameter set to null if ComposedMailMessage.hasRecipients() is false; otherwise ComposedMailMessage.getRecipients() is passed.
abstract  MailMessage sendMailMessage(ComposedMailMessage transportMail, ComposeType sendType, javax.mail.Address[] allRecipients)
          Sends a mail message
 MailMessage sendRawMessage(byte[] asciiBytes)
          Sends specified message's raw ascii bytes.
abstract  MailMessage sendRawMessage(byte[] asciiBytes, javax.mail.Address[] allRecipients)
          Sends specified message's raw ascii bytes.
abstract  void sendReceiptAck(MailMessage srcMail, java.lang.String fromAddr)
          Sends a receipt acknowledgment for the specified message.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MailTransport

public MailTransport()
Method Detail

getInstance

public static final MailTransport getInstance(com.openexchange.session.Session session)
                                       throws MailException
Gets the proper instance of mail transport parameterized with given session.

Note: Don't forget to call final close() on obtained mail transport:

 final MailTransport mailTransport = MailTransport.getInstance(session);
 try {
     // Do something
 } finally {
     mailTransport.close();
 }
 

Parameters:
session - The session
Returns:
A proper instance of MailTransport
Throws:
MailException - If instantiation fails

getInstance

public static final MailTransport getInstance(com.openexchange.session.Session session,
                                              int accountId)
                                       throws MailException
Gets the proper instance of mail transport for session user's default transport account.

Note: Don't forget to call final close() on obtained mail transport:

 final MailTransport mailTransport = MailTransport.getInstance(session, accountId);
 try {
     // Do something
 } finally {
     mailTransport.close();
 }
 

Parameters:
session - The session
Returns:
A proper instance of MailTransport
Throws:
MailException - If instantiation fails

sendMailMessage

public MailMessage sendMailMessage(ComposedMailMessage transportMail,
                                   ComposeType sendType)
                            throws MailException
Sends a mail message

This is a convenience method that invokes sendMailMessage(ComposedMailMessage, ComposeType, Address[]) with the latter parameter set to null if ComposedMailMessage.hasRecipients() is false; otherwise ComposedMailMessage.getRecipients() is passed.

Parameters:
transportMail - The mail message to send (containing necessary header data and body)
sendType - The send type
Returns:
The sent mail message
Throws:
MailException - If transport fails

sendMailMessage

public abstract MailMessage sendMailMessage(ComposedMailMessage transportMail,
                                            ComposeType sendType,
                                            javax.mail.Address[] allRecipients)
                                     throws MailException
Sends a mail message

Parameters:
transportMail - The mail message to send (containing necessary header data and body)
sendType - The send type
allRecipients - An array of addresses to send this message to; may be null to extract recipients from message headers TO, CC, BCC, and NEWSGROUPS.
Returns:
The sent mail message
Throws:
MailException - If transport fails

sendRawMessage

public MailMessage sendRawMessage(byte[] asciiBytes)
                           throws MailException
Sends specified message's raw ascii bytes. The given bytes are interpreted dependent on implementation, but in most cases it's treated as an rfc822 MIME message.

This is a convenience method that invokes sendRawMessage(byte[], Address[]) with the latter parameter set to null.

Parameters:
asciiBytes - The raw ascii bytes
Returns:
The sent mail message
Throws:
MailException - If sending fails

sendRawMessage

public abstract MailMessage sendRawMessage(byte[] asciiBytes,
                                           javax.mail.Address[] allRecipients)
                                    throws MailException
Sends specified message's raw ascii bytes. The given bytes are interpreted dependent on implementation, but in most cases it's treated as an rfc822 MIME message.

Parameters:
asciiBytes - The raw ascii bytes
allRecipients - An array of addresses to send this message to; may be null to extract recipients from message headers TO, CC, BCC, and NEWSGROUPS.
Returns:
The sent mail message
Throws:
MailException - If sending fails

sendReceiptAck

public abstract void sendReceiptAck(MailMessage srcMail,
                                    java.lang.String fromAddr)
                             throws MailException
Sends a receipt acknowledgment for the specified message.

Parameters:
srcMail - The source mail
fromAddr - The from address (as unicode string). If set to null, user's default email address is used as value for header From
Throws:
MailException - If transport fails

ping

public abstract void ping()
                   throws MailException
Pings the transport server to check if a connection can be established.

Throws:
MailException - If the ping fails

close

public abstract void close()
                    throws MailException
Closes this mail transport

Throws:
MailException - If closing fails

getTransportConfig

public abstract TransportConfig getTransportConfig()
                                            throws MailException
Returns the transport configuration appropriate for current user. It provides needed connection and login information.

Returns:
The transport configuration
Throws:
MailException